ExamVeda
Login
Home
This question belongs to C Program Control Structures
Control Structures
?

What will be the final value of the digit?
void main()
{
   int digit = 0;
   for( ; digit <= 9; )
   digit++;
   digit  *= 2;
   --digit;
}

Answer & Solution
Correct Answer: Option C
First of all for loop have no braces so for loop on have only next line in its body.
for( ; digit <= 9; )
digit++;
After completing for loop digit = 10;
next statement digit *= 2; i.e digit = digit * 2 = 20;
next statement digit--; i.e 20-- => 19
So final value of digit is 19
Examveda
Question posted by Examveda
Community

Join the Discussion

4 Comments
Geeky Sharma
Geeky Sharma 4 years ago
Digit got increamented until it became 9 then at last it got increamented to 10 then condition got false and loop terminated.
Digit *= 2 resulted in Digit = 20
-- Digit resulted in Digit = 19

Hare Krishna!
Umang Mahant
Umang Mahant 9 years ago
ans should be 15!
Ankit Pare
Ankit Pare 10 years ago
After Compilation the Output is 15 but not 19 please give me the explanation
Shyam Prakash
Shyam Prakash 10 years ago
can u give the explanation