Multiple Choice Quiz

1. Which of the following is an illegal use of the keyword "auto"?

2. What is the output from the following code fragment?
  char var = 'a';
  {
    int var = 10;
    std::cout << var;
  }
  std::cout << var << std::endl;

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

4. You have two variables 'day' and 'temperature'. You want to stop a loop if either day becomes greater than 365 or if temperature goes below zero. You want to keep looping as long as neither of those conditions triggers. What should your loop look like?

5. How is std::npos used in the standard library?

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

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

8. Assuming that the variable cost is set to 5.1, how can you print it as "$5.10"?

9. What does the following line of code do?
  assert(x == 10);

10. If we have an array defined as "int my_array[3117];", one way to get a pointer to index 42 is "&(my_array[42])". What is another way?


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.