WorksheetsVariables in C++
Total questions: 10
Worksheet time: 8mins
What is the final value of x in the following code segment?
int x = 7;
x += 2*x;
63
21
81
This code segment will not compile.
What is the final value of y in the following code segment?
int y = 3 * 7 % 8 + 1 * 4;
9
24
25
6
This code segment will not compile.
What is the final value of x in the following code segment?
double x = 7/2;
3 1/2
3.5
3.0
This code segment will not compile.
What are the final values of y and z in the following code segment?
int z =4;
int y = 3 + z--;y = 7, z = 3
y = 7, z = 4
y = 6, z = 3
y = 6, z = 4
This code segment will not compile.
What is the final value of y in the following code segment?
double y = 2;
int z = 3;
y /= z + 1;y = 1.0
y = 2.0
y = 0.5
y = 0.0
This code segment will not compile.
What is the final value of w in the following code segment?
int w = int(3 / 2) + 5 % 10 - 3.5;
-2
3
-3
2
This code segment will not compile.
What is the final value of x in the following code segment?
(Assume the header file <cmath> has been included.)
double x = pow(2, 3) + 1 / 2;
9.5
8.5
8.0
9.0
This code segment will not compile.
What is the final value of x in the following code segment?
(Assume the header file <cmath> has been included.)
double x = 15 / sqrt(4.0) - 10 % 3;
6.5
6.0
0.0
-0.5
This code segment will not compile.
What are the final values of x and y in the following code segment?
int x = 3;
int y = ++x * 5 / 2;
x = 3, y = 10
x = 4, y =7
x = 4, y = 10
x = 3, y = 7
This code segment will not compile.
What is the final value of y in the following code segment?
int x = 1234;
int y = x % 10 + x / 10 % 10;
y = 34
y = 7
y = 38
y = 10
This code will cause an error due to division by zero.
