C++ Language MCQs with Answers [ 4320702 ]

Computer Bits Daily
3 min readMay 9, 2023

Here are C++ MCQs with answers and explanations:
What is the output of the following code?
int x = 5;
cout << x++ << ++x << x;

Answer: 567
Explanation: The first cout statement outputs the value of x (5), then increments x to 6. The second cout statement increments x to 7, then outputs the value of x (7). The third cout statement outputs the value of x (7).

Download free C++ mcq app: https://play.google.com/store/apps/details?id=com.cplusplusmcq.programs.interviewcomputerbitsdaily

What is the output of the following code?
int x = 5;
cout << ++x << x++ << x;

Answer: 678
Explanation: The first cout statement increments x to 6, then outputs the value of x (6). The second cout statement outputs the value of x (6), then increments x to 7. The third cout statement outputs the value of x (7).

What is the output of the following code?
int x = 5;
cout << x << x << x;

Answer: 555
Explanation: All three cout statements output the value of x (5).

Download free C++ mcq app: https://play.google.com/store/apps/details?id=com.cplusplusmcq.programs.interviewcomputerbitsdaily

What is the output of the following code?
int x = 5;
cout << x << “ “ << ++x << “ “ << x++;

Answer: 5 6 6
Explanation: The first cout statement outputs the value of x (5), followed by a space. The second cout statement increments x to 6, then outputs the value of x (6), followed by a space. The third cout statement outputs the value of x (6), then increments x to 7.

What is the output of the following code?
int x = 5;
int y = 7;
cout << (x > y ? x : y);

Answer: 7
Explanation: The ternary operator (x > y ? x : y) evaluates to y because x is not greater than y.

What is the output of the following code?
int x = 5;
int y = 7;
cout << (x < y ? x++ : y++);
cout << x << y;

Answer: 57
Explanation: The ternary operator (x < y ? x++ : y++) evaluates to x++ because x is less than y. The first cout statement outputs the value of x (5), then increments x to 6. The second cout statement outputs the values of x (6) and y (7).

What is the output of the following code?
int x = 5;
int y = 7;
cout << (x > y ? x++ : y++);
cout << x << y;

Answer: 78
Explanation: The ternary operator (x > y ? x++ : y++) evaluates to y++ because x is not greater than y. The first cout statement outputs the value of y (7), then increments y to 8. The second cout statement outputs the values of x (5) and y (8).

What is the output of the following code?
int x = 5;
int y = 7;
cout << (x > y ? x++ : ++y);
cout << x << y;

Answer: 8 6 8
Explanation: The ternary operator (x > y ? x++ : ++y) evaluates to ++y because x is not greater than y. The first cout statement outputs the value of y (8), then increments y to 9. The second cout statement outputs the values of x (6) and y (9).

What is the output of the following code?
int x = 5;
int y = 7;
cout << (x < y ? x++ : ++y);
cout << x << y;

Answer: 6 6 8
Explanation: The ternary operator (x < y ? x++ : ++y) evaluates to x++ because x is less than y. The first cout statement outputs the value of x (6), then increments x to 7. The second cout statement outputs the values of x (7) 10. What is the output of the following code?
int x = 5;
int y = 7;
int z = 9;
cout << (x > y ? (y > z ? x : y) : (y < z ? y : x));

Answer: 5
Explanation: The nested ternary operator evaluates to x because x is not greater than y, and y is not less than z. Therefore, the outer ternary operator evaluates to x. The cout statement outputs the value of x (5).

Computer Course free learning app: https://play.google.com/store/apps/details?id=com.computerdictionary.mcqtutorial.computerbitspradip

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Computer Bits Daily
Computer Bits Daily

Written by Computer Bits Daily

Learning Computer skills and Computer technology by learning and sharing

No responses yet