LearnFrenzy
Sign in Take a free test

C Loops · Loops MCQ · Question 11

while (n--) with n = 3 – how many passes? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

With int n = 3;, how many times does while (n--) { … } run, and what is n afterwards?

  • A 3 times, n = 0
  • B 3 times, n = -1 Correct
  • C 2 times, n = 0
  • D 4 times, n = -1
Correct Answer: Option B

The test uses the old value and then decrements: 3, 2, 1 are true (3 passes); the test with 0 is false but still decrements, leaving n at −1.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links