Home / C Programming / Expressions :: Discussion

Discussion :: Expressions

  1. What will be the output of the program?

    #include
     int main() 
    {   
         int i=4, j=-1, k=0, w, x, y, z;    
         w = i || j || k;   
         x = i && j && k;     
         y = i || j &&k;    
         z = i && j || k;   
         printf("%d, %d, %d, %d\n", w, x, y, z);  
         return 0;
     } €‹
    €‹€‹€‹€‹€‹€‹
    

  2. A.

    1, 1, 1, 1

    B.

    1, 1, 0, 1

    C.

    1, 0, 0, 1

    D.

    1, 0, 1, 1

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, -1, 0 respectively.

    Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1

    Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0

    Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1

    Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.

    Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".


Be The First To Comment