Multiple Choice Quiz

1. What is the difference between the keyword struct and the keyword class?

2. 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?

3. Which of these numeric types is represented using the most bytes in C++?

4. Which of the following is NOT a good reason a to define a member variable in the private section of a class definition?

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

6. What would be the output of the following C++ code?
  std::string main_str{"This is a test string."};
  auto pos = main_str.find("is");
  std::cout << pos << std::endl;

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

8. If I created an array of strings with "std::string word_list[5000]", what should I do when I'm done using word_list?

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

10. What is a difference between pointers and references 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.