Multiple Choice Quiz

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

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

3. Which of the following is a correct syntax for defining a lambda function in C++?

4. Given that a Node is defined as:
  struct Node{
    int value = 0;
    Node * next = nullptr;
  };
Consider the following code:
  Node * node = new Node;
  node->value = 100;
  node->next = new Node;
  std::cout << node->next->value;
  delete node;
  delete node->next;
Which of the following is a problem with this code:

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

6. If you make a function call TestFunction('a') and all of the following options are available, which version of the function will be called?

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

8. When compiling a large C++ project with many files, which of the following is NOT always good advice?

9. What is a difference between a native array (such as "int a[100]") and std::vector (such as "std::vector<int> v(100)")?

10. Which of these numeric types is represented using the fewest bytes 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.