ExamVeda
Login
Home
1
What is the syntax for the 'if' statement in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
2
What is the purpose of the 'else' statement in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
3
What is the correct syntax for the 'switch' statement in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
4
What will be the output of the following code: int x = 10; if (x > 5) cout << "Hello"; else cout << "Goodbye"; in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
5
What does the 'break' statement do in a loop in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
6
What is the correct syntax for the 'while' loop in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
7
What will be the output of the following code: int i = 0; while (i < 5) { cout << i << " "; i++; } in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
8
What is the purpose of the 'default' case in a 'switch' statement in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
9
What is the syntax for the 'do-while' loop in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
10
What will be the output of the following code: for (int i = 5; i >= 0; --i) { cout << i << " "; if (i == 3) break; } in C++?
Discuss
Answer & Solution
Answer: Option B
Solution:
The given code is a for loop in C++:

for (int i = 5; i >= 0; --i) {
    cout << i << " ";
    if (i == 3) break;
}

This loop initializes i to 5 and decrements it in each iteration until i becomes less than 0.

On each iteration, it prints the current value of i followed by a space.

When i becomes 3, the if condition becomes true and the break statement terminates the loop.

Therefore, the values printed are: 5 4 3

No further values (like 2, 1, 0) are printed because the loop exits when i == 3.

Hence, the correct output is: 5 4 3