Home / C Programming / Structures, Unions, Enums :: Discussion

Discussion :: Structures, Unions, Enums

  1. What will be the output of the program ?

     #include
    
      int main() 
      {   
          union a   
          {      
             int i;     
             char ch[2];   
          };     
          union a u;    
          u.ch[0]=3;     
          u.ch[1]=2;     
          printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);     
         return 0;
     }
    

     

  2. A.

    3, 2, 515

    B.

    515, 2, 3

    C.

    3, 2, 5

    D.

    515, 515, 4

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    The system will allocate 2 bytes for the union.

    The statements u.ch[0]=3; u.ch[1]=2; store data in memory as given below.

     


Be The First To Comment