C++ Programming MCQs — Programming
3 practice MCQs
The correct answer is marked on every question, with its full explanation.
ProgrammingC++ Programming PPSC FPSC NTSID: NWF-034
What is the output of this C++ code? int x = 10; x += 5; cout << x;
- A15 ✓ Correct answer
- B10
- C5
- D50
✓ Correct answer: 15
Full explanation
The output is 15. The statement x += 5 adds 5 to 10, so x becomes 15, and cout prints 15. Why the others are wrong: 10 — that is the value of x before 5 is added. 5 — that is the amount added, not the final value. 50 — 10 plus 5 is 15, not 50.
ProgrammingC++ Programming PPSC FPSC NTSID: PROG-002
What is the output of this C++ code? int a = 7; int b = 2; cout << a - b;
- A3
- B9
- C14
- D5 ✓ Correct answer
✓ Correct answer: 5
Full explanation
7 minus 2 is 5, so the program prints 5. Why the others are wrong: 9 — 9 is 7 plus 2, not 7 minus 2. 14 — 14 is 7 times 2, not 7 minus 2. 3 — 3 is not the result of 7 minus 2.
ProgrammingC++ Programming PPSC FPSC NTSID: PROG-007
What is the output of this C++ code? int a = 4; int b = 3; cout << a * b;
- A1
- B7
- C12 ✓ Correct answer
- D43
✓ Correct answer: 12
Full explanation
12. The code multiplies a by b, so 4 * 3 = 12. Why the others are wrong: '7' — this is 4 + 3, but the code multiplies, it does not add. '1' — this is 4 - 3, but the code multiplies, it does not subtract. '43' — this joins the two numbers as text, but cout prints the result of the multiplication, not the two numbers side by side.
Practise these MCQs interactively →
← Programming MCQs