1. What is the difference between the keyword struct and the keyword class?
struct
class
2. 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++;
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?
std::string
age_str
long
age
long age = dynamic_cast<long>(age_str);
long age = std::to_string(age_str);
long age = std::stol(age_str);
long age = static_cast<long>(age_str);
4. Assuming that x, y, and z are all defined, which of the following is true in c++:
x => z
y != z
x === y
x < y < z
5. Which of the following is a correct syntax for defining a lambda function in C++?
auto f = (int x) { return x * x; };
[](int x){ return x * x; };
(int x) => x * x;
lambda(int x) { return x * x; };
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)")?
int a[100]
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;
char var1 = 'b';
if (var1 == 'b') {
int var2 = 10;
}
std::cout << var1 << var2 << std::endl;
bb
b
b10
10b
9. What is the value of var2 after the following code executes? int var1 = 5; var1 += 5; int var2 = 2 * ++var1;
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; }
for (int i = 0; i < 6; ++i) {
if (i == 2) continue;
if (i == 4) break;
std::cout << i;
01
0123
013
0134
2
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.