1. Which of the following will initialize the variable x to the numerical value 0?
char x = "";
char x = '0';
char x = '\0';
char x = std::endl;
2. What will happen if you do not explicitly initialize an int variable?
int
3. When would you mark a stand-alone function as const?
const
4. What is the value of var2 after the following code executes? int var1 = 5; var1 += 5; int var2 = 2 * var1++;
var2
int var1 = 5;
var1 += 5;
int var2 = 2 * var1++;
5. Which of the following is an illegal use of the keyword "auto"?
const auto & my_err = std::cerr;
auto i;
auto my_str = std::string("Test.");
auto my_var = std::string("abcd");
6. Why should you use "include guards" (or #pragma once) in your header files?
#pragma once
7. What will the following code print? char x = 'A'; while (x <= 'E') { std::cout << x++; }
char x = 'A';
while (x <= 'E') {
std::cout << x++;
}
ABCDE
BCDEF
ABCD
A
ABCDEF
8. If you make a function call TestFunction(91), which version of the function will be called?
void TestFunction(double param);
void TestFunction(int param1, int param2=0);
void TestFunction(std::string param);
void TestFunction();
9. What will the following code print? for (int i = 0; i < 6; ++i) { if (i == 2) continue; if (i == 4) break; std::cout << i; }
for (int i = 0; i < 6; ++i) {
if (i == 2) continue;
if (i == 4) break;
std::cout << i;
013
0134
012345
01
0123
10. What is the correct syntax for declaring a template function in C++?
template <typename T> void foo(T);
void foo(T) <- template <typename T>;
void foo<template T>(T);
<template typename T> void foo(T);
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.