Practical C++ Programming by manish baranwal

Comenzar desde el principio
                                        

volatile a special variable whose value may be changed by things outside the program .

Used for things like memory mapped I/O.

const a named value that cannot be changed .

reference an alias or second name for an already declared variable .

extern a variable that is defined in another file. Actually, C++ won’t get mad at you i f

you define it in the current file.

13. Why must you use the notation static_cast<int>(very_short) to write a very short

number (a.k.a. a character variable)? What would happen if you wrote it out without the int

wrapper?

The static_cast< int>(x) notation changes the character variable’s type from

character to integer for the purpose of the write. If the int wrapper is left off, the C++

would write the character variable out not as a very short integer but as a single character.

After all, C++ does not know if you are using a character variable to hold a character or a

very short int.

14. Define side effect.

A side effect is an operation that occurs in addition to the main operation specified in a

statement.

15. Why are side effects bad things?

The confuse the code and can easily cause unexpected things to happen. Using them can

make the code dependent on things like the evaluation order of operands. They save

space in the source code at the expense of clarity and reliability.

Page 18

Chapter 6: Decision and

Control Statements

Once a decision was made, I did not worry about it afterward.

— Harry Truman

Teacher’s Notes

Student are now introduced to the fact that computers cannot only do computitions, but can also make

decisions.

Decision statements for the most part are fairly straight-forward and fairly simple, as are the relation

operators.

A conditional statement works on the single statement that follows it. Multiple statements my be

grouped together by curly braces ({}) and treated as a single statement.

The if/else statement is ambiguous as we can see in Slide 7. One of the things emphasized in this book is

practical programming, and practically speaking you don’t have to worry about language weirdness if

you avoid it.

Note: For the purist in your class, the ambiguity is resolved by placing the else clause with the nearest if.

(Answer b).

Then show the students how to use decision and control statements by writing a program to print out a

series of Fibonacci numbers.

Finally, teach the student the dangers of using = inside an if or while statement. The one mistake you

Has llegado al final de las partes publicadas.

⏰ Última actualización: Nov 04, 2012 ⏰

¡Añade esta historia a tu biblioteca para recibir notificaciones sobre nuevas partes!

Practical C++ Programming by manish baranwalDonde viven las historias. Descúbrelo ahora