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
Join The Discussion
Comments ( 4 )
Related Questions on Control Structures
Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
In C, what is the purpose of the 'break' statement within a loop?
A. Continue to the next iteration
B. Exit the program
C. Terminate the loop and exit it
D. Skip the current iteration
What is the purpose of the 'else' statement in C's 'if-else' control structure?
A. Execute the 'if' block
B. Execute the 'else' block
C. Execute both 'if' and 'else' blocks
D. Skip the 'if' block
Which control structure is used to make a decision between two or more alternatives in C?
A. switch case
B. for loop
C. if statement
D. while loop
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