Important MCQ

int n=5; while(n>0) n--; final value of n is

Q.int n=5; while(n>0) n--; final value of n is

A) 1
B) 5
C) -1
D) 0
Correct Answer:
Option D
Detailed Explanation:
D) 0 is correct. A while loop checks its condition before each iteration, so it may run zero times. The loop body must update state when needed to avoid an unintended infinite loop.