What will be the output of the following code: for (int i = 5; i >= 0; --i) { cout << i << " "; if (i == 3) break; } in C++?
A. Compilation error
B. 5 4 3 0
C. 5 4 3 2 1 0
D. 5 4 3 0 1
Answer: Option C
A. Compilation error
B. 5 4 3 0
C. 5 4 3 2 1 0
D. 5 4 3 0 1
Answer: Option C
What is the syntax for the 'if' statement in C++?
A. if (condition) then statement;
B. if (condition) then { statement; }
C. if { condition } then { statement; }
D. if (condition) { statement; }
What is the purpose of the 'else' statement in C++?
A. Executes after the 'if' block
B. Executes before the 'if' block
C. Executes when the 'if' condition is false
D. Executes regardless of the 'if' block
What is the correct syntax for the 'switch' statement in C++?
A. switch (expression) { case constant1: statement1; case constant2: statement2; }
B. switch (expression) { case constant1: statement1; break; case constant2: statement2; break; default: defaultStatement; }
C. switch (expression) { case constant1: statement1; default: defaultStatement; }
D. None of the above
A. Compilation error
B. HelloGoodbye
C. Hello
D. Goodbye
Join The Discussion