Examveda
Examveda

What will be the final value of the 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

This Question Belongs to C Program >> Control Structures

Join The Discussion

Comments ( 4 )

  1. Geeky Sharma
    Geeky Sharma :
    2 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!

  2. Umang Mahant
    Umang Mahant :
    7 years ago

    ans should be 15!

  3. Ankit Pare
    Ankit Pare :
    7 years ago

    After Compilation the Output is 15 but not 19 please give me the explanation

  4. Shyam Prakash
    Shyam Prakash :
    7 years ago

    can u give the explanation

Related Questions on Control Structures