C
O
D
SE
R
U
N
, S
C
O
D
SE
R
U
N
, S
C
O
D
SE
R
U
N
, n = (n++) + (n++);
the value of n is guaranteed to be 3 after the second line executes.
Answer: False.
Explanation: Some compilers may give the value 3. The result of such code is dependent
on the compiler implementation. The C++ Standard says such code is illegal, and the
Standard says the results are undefined, meaning the compiler can do anything with it
that suits the compiler writer. One of my compilers gives the value 4 to n.
N
14. If we execute the code fragment in an otherwise complete, correct program:
n = 1;
cout << n++ << " " << n++ << " " << n++ << endl;
U
the output is guaranteed to be 1 2 3.
Answer: False.
R
Explanation: The code is illegal because its execution depends on the order of evaluation
of arguments. Various compilers give different answers. One compiler this writer uses
SE
gives 3 2 1.
15. C++ uses only /* */ for comments.
Answer: False.
Explanation: C++ uses /* */ comments and // “here to the end of the line”
D
comments.
16. A program’s comments should connect the program code to the problem being
O
solved.
Answer: True.
C
Explanation: The purpose of comments in a program is to help the human reader of the
code to connect the program to the problem being solved. Comments are so important
there is an aphorism, often quoted by expert programmers: “If the comments and the code
S
disagree, then both are probably wrong.
17. A program should have a comment on every line.
Answer: False.
Explanation: This would be satisfactory only on a very complicated assembly language
program for an inexperienced programmer.
18. Comments have no value whatsoever and do not belong in a program.