Home / C Programming / Control Instructions :: Discussion

Discussion :: Control Instructions

  1. What will be the output of the program?

     #include 
     int main()
     {   
        int a = 300, b, c;   
        if(a >= 400)     
             b = 300;     
        c = 200;     
        printf("%d, %d, %d\n", a, b, c);       
        return 0; 
    } 
    

  2. A.

    300, 300, 200

    B.

    Garbage, 300, 200

    C.

    300, Garbage, 200

    D.

    300, 300, Garbage

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    Step 1: int a = 300, b, c; here variable a is initialized to '300', variable b and c are declared, but not initialized.
    Step 2: if(a >= 400) means if(300 >= 400). Hence this condition will be failed.
    Step 3: c = 200; here variable c is initialized to '200'.
    Step 4: printf("%d, %d, %d\n", a, b, c); It prints "300, garbage value, 200". because variable b is not initialized.


Be The First To Comment