Multiple Choice Quiz

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

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

3. If you have a variable of type std::string called "age_str" which holds only digit characters and you want to convert it to a long called "age", which of these lines will work?

4. Assuming that x, y, and z are all defined, which of the following is true in c++:

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

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

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

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. What is the value of var2 after the following code executes?
  int var1 = 5;
  var1 += 5;
  int var2 = 2 * ++var1;

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


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.