?
What will be the final value of the digit?
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;
}
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
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
Join the Discussion
Login to post a comment or share your explanation.
LoginDigit *= 2 resulted in Digit = 20
-- Digit resulted in Digit = 19
Hare Krishna!