What will be the final value of the digit?
void main()
{
int digit = 0;
for( ; digit <= 9; )
digit++;
digit *= 2;
--digit;
}
void main()
{
int digit = 0;
for( ; digit <= 9; )
digit++;
digit *= 2;
--digit;
}
A. -1
B. 17
C. 19
D. 16
E. 20
Answer: Option C
Solution (By Examveda Team)
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
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!
ans should be 15!
After Compilation the Output is 15 but not 19 please give me the explanation
can u give the explanation