Multiple Choice Quiz

1. Which of the following is NOT a correct way to indicate a newline at the end of "Hello World!"?

2. Which of these numeric types is represented using the fewest bytes in C++?

3. If I have an std::string called name, with the contents "John Wilkes Booth", and another called middle, which of the following techniques will set middle to be "Wilkes"?

4. What is the value of y after these lines are run in C++?
  int x = 6;
  int y = 4 + x * 3 - 1;

5. What error is in the following function?
  template <typename T>
  T & Multiply(const T in1, const T in2) {
    return in1 * in2;
  }

6. You want to execute code if either var1 is true or var2 is true, but not if they are both true. Given that both variables are type bool, three of the following techniques work; which one will NOT work?

7. What is the output of the following program:
  std::map<int, std::string> star_map;
  star_map[0] += "*";
  star_map[2] += "*";
  star_map[3] += "*";
  star_map[0] += "*";
  std::cout << star_map[0] << "-" << star_map[1] << "-" << star_map[2];

8. What is the output from the following code fragment?
  char var1 = 'b';
  if (var1 == 'b') {
    int var2 = 10;
  }
  std::cout << var1 << var2 << std::endl;

9. Given the following templated function:
  template <typename T>
  void PrintBoth(T in1, T in2) {
    std::cout << in1 << ", " << in2 << std::endl;
  }
Which function call will cause a compilation error?

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


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.