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-033
What is the output of this C code? int a = 5, b = 2; printf("%d", a / b);
- A2 ✓ Correct answer
- B2.5
- C3
- D0
✓ Correct answer: 2
Full explanation
The output is 2. In C, dividing two integers gives an integer result, so 5 / 2 is 2 and the remainder is dropped. Why the others are wrong: 2.5 — this would be the result only if one of the numbers were a float or double. 3 — 5 divided by 2 is not 3. 0 — 5 divided by 2 is not 0.
ProgrammingC Programming PPSC FPSC NTSID: PROG-001
What is the output of this C code? printf("%d", 10 % 3);
- A0
- B3
- C3.33
- D1 ✓ Correct answer
✓ Correct answer: 1
Full explanation
The % operator gives the remainder, and 10 divided by 3 leaves a remainder of 1, so the output is 1. Why the others are wrong: 3 — 3 is the quotient of 10 divided by 3, not the remainder. 3.33 — the % operator gives a whole-number remainder, not a decimal. 0 — 10 is not exactly divisible by 3, so the remainder is not 0.
ProgrammingC Programming PPSC FPSC NTSID: PROG-006
What is the output of this C code? printf("%d", 2 + 3 * 4);
- A20
- B9
- C24
- D14 ✓ Correct answer
✓ Correct answer: 14
Full explanation
14. Multiplication comes before addition in C, so 3 * 4 = 12 and then 2 + 12 = 14. Why the others are wrong: '20' — this comes from adding first (2 + 3 = 5) and then multiplying by 4, but C multiplies first. '24' — this comes from multiplying 2 * 3 * 4, which is not what the code does. '9' — this comes from adding 2 + 3 + 4, but the code multiplies 3 by 4.
Practise these MCQs interactively →
← Programming MCQs