-
What is the difference in results from the left and right
program parts:
if (1 == 2) if (1 == 2) {
cout << "Strange "; cout << "Strange ";
cout << "Mathematics"; cout << "Mathematics";}
-
Strange Mathematics / Strange Mathematics.
-
Mathematics / No output.
-
No output / No output.
-
Which program part which is correct:
if (1 == 2) if (1 == 2)
cout << "Strange "; cout << "Strange ";
cout << "Mathematics";
else else
cout << "Plain "; cout << "Plain ";
cout << "Mathematics"; cout << "Mathematics";
-
Left.
-
Right.
-
Both are correct, but left is shorter.
-
For if ... if ... else ..., does the else belong
to the first or second if? (The dots are the conditions and
statements or compound statements)
-
First.
-
Second.
-
This is not allowed.
-
How could you safely reformulate the previous construct so
that confusion is not possible?
-
if ... else if ... else ...
-
if ... else ... if ... else ...
-
if ... { if ... else ...}
-
Which program part produces correct output for any a, b:
if (a<b || a==b) if (a<b && a==b)
cout << "a is not > b"; cout << "a is not > b";
else cout << "a > b"; else cout << "a > b";
-
Left.
-
Right.
-
Both.
-
The condition a>b is equivalent to:
-
b<a.
-
b<a || b==a.
-
Both.
-
The condition a<=b is equivalent to:
-
b>a || b==a
-
! (b<=a)
-
Neither
-
The condition a<b is equivalent to:
-
b>a || b==a
-
! (b<=a)
-
Both.
-
The expression a<1 || a>3 && a!=0 is equivalent to:
-
a<1 || (a>3 && a!=0)
-
(a<1 || a>3) && a!=0
-
So, is the previous expression true when a is zero?
-
Yes.
-
No.
-
It is too soon to tell.
-
What does the next program part write:
for (i=2; i<5; i++) cout << i;
-
1 2 3 4 5
-
2 3 4 5
-
2 3 4
-
2 4
-
2
-
5
-
6
-
Nothing.
-
What does the next program part write:
for (i=2; i<5; i++); cout << i;
-
1 2 3 4 5
-
2 3 4 5
-
2 3 4
-
2 4
-
2
-
5
-
6
-
Nothing.
-
What does the next program part write:
for (i=2; i<5; i=i+2) cout << i;
-
1 2 3 4 5
-
2 3 4 5
-
2 3 4
-
2 4
-
2
-
5
-
6
-
Nothing.
-
What does the next program part write:
for (i=2; i<5; i=i+3) cout << i;
-
1 2 3 4 5
-
2 3 4 5
-
2 3 4
-
2 4
-
2
-
5
-
6
-
Nothing.
-
What does the next program part write:
for (i=5; i<5; i=i+3) cout << i;
-
1 2 3 4 5
-
2 3 4 5
-
2 3 4
-
2 4
-
2
-
5
-
6
-
Nothing.
-
How many exclamation marks does the next program part write:
for (i=2; i<5; i--) cout << "!";
-
None.
-
One.
-
Infinitely many.
-
What does the next program part write:
for (i=2; i>0; i--) cout << i;
-
0 1 2
-
2 1 0
-
2 1
-
1 0
-
1
-
Nothing.
-
Can you leave the initialization, test, and increment away from
a for loop? If so, what would happen?
-
No, this will not compile.
-
Yes, but the statement in the loop will not execute even once.
-
Yes, but I will lose credit for poor coding.
-
What is the result of i=0;while (i<2) cout << i++;?
-
This will not compile.
-
0 1 2
-
0 1
-
1 2
-
1
-
What is the result of while (1==1) cout << '!';?
-
The cout statement is not executed even once.
-
It writes a single exclamation mark.
-
It keeps writing exclamation marks until you manage to kill
off the process.
-
What is the result of while (1) cout << '!';?
-
This will not compile, since a condition, not a number, is
needed within the parentheses of the while.
-
The cout statement is not executed even once.
-
It writes a single exclamation mark.
-
It keeps writing exclamation marks until you manage to kill
off the process.
-
What is the result of while (0) cout << '!';?
-
This will not compile, since a condition, not a number, is
needed within the parentheses of the while.
-
The cout statement is not executed even once.
-
It writes a single exclamation mark.
-
It keeps writing exclamation marks until you manage to kill
of the process.