Getting started with C++ - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. In C++, the token// is used for:
  A. integer division
  B. concatenation
  C. comments
  D. exponentiation
  The correct answer is C. It is the rest-of-line comment symbol.

2. The function strlen() computes:
  A. the number of non-whitespace characters in a string
  B. the length of a string, not including the null terminator
  C. the number of alphabetical characters in a string
  D. the length of a string, including the null terminator
  The correct answer is B.
It is the standard library function for the length of a null-terminated string. The function strlen() returns the length of the string, not including the null terminator.

3. In C++, cout is found in which library file?
  A. ctype.h
  B. stdlib.h
  C. math.h
  D. iostream.h
  The correct answer is D.
The standard C++ library iostream.h contains the variable cout.

4. One difference between C++ and C is that C++:
  A. has long double
  B. is block structured
  C. has declarations that can go after executable code
  D. has no do-while statement
  The correct answer is C.
Declarations in C++ can go most anywhere in executable code, but in C they must be at the head of blocks.


5. Assume that before the following cast, i is type int. What will i be after the cast is performed?
y = static_cast<float>(i);
  A. float
  B. char
  C. int
  D. double
  The correct answer is C.
A static_cast does not change the type of the variable being cast.

6. The standard identifier cin is used for:
  A. a compiler flag
  B. standard output
  C. standard input
  D. the integer -1
  The correct answer is C.
The variable cin is used for standard input. The variable cout is for standard output.

7. In enum names {Harold, Phillip, Ira, Morris} the enumerator Morris is the integer value constant:
  A. 4
  B. 3
  C. 5
  D. system dependent
  The correct answer is B.
Harold is by default the constant 0, Phillip 1, Ira 2, and Morris is, therefore, 3.

8. The keyword endl:
  A. defines a symbolic constant
  B. specifies that a function is to be compiled, if possible, as inline code
  C. provides assertion testing
  D. flushes the output stream and adds a new line
  The correct answer is D.
The keyword endl is a manipulator, which causes the output stream to be flushed and a new line to be added. To define a symbolic constant or named literal, use the const keyword. To specify that a function be compiled as inline code, use the inline keyword. Assertion testing is provided in C++ by using the assert.h library.