Multiple Choice Quiz

1. Which of the following will initialize the variable x to the numerical value 0?

2. What will happen if you do not explicitly initialize an int variable?

3. When would you mark a stand-alone function as const?

4. What is the value of var2 after the following code executes?
  int var1 = 5;
  var1 += 5;
  int var2 = 2 * var1++;

5. Which of the following is an illegal use of the keyword "auto"?

6. Why should you use "include guards" (or #pragma once) in your header files?

7. What will the following code print?
  char x = 'A';
  while (x <= 'E') {
    std::cout << x++;
  }

8. If you make a function call TestFunction(91), which version of the function will be called?

9. What will the following code print?
  for (int i = 0; i < 6; ++i) {
    if (i == 2) continue;
    if (i == 4) break;
    std::cout << i;
  }

10. What is the correct syntax for declaring a template function in C++?


Click Check Answers to identify any errors and try again. Click Show Answers if you also want to know which answer is the correct one.