Multiple Choice Quiz

1. !If you are creating a C++ class, you can explicitly set certain functions to be default. Which of the following is allowed in class called "DefaultTest"?

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

3. You have a "Book" class and want to add a member function called "CountWord" that takes a word as its parameter and returns the number of times that word was used. Which of the following is the best way to declare this function so that it will function correctly and be callable in a variety of contexts?

4. What is a difference between pointers and references in C++? +

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

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

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

8. Which of the following is NOT a legal function declaration

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

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.