C : STRUCTURE AND UNION


STRUCTURE AND UNION



STRUCTURE :


  1. STRUCTURE is similar to array with a difference that it can store values of different datatypes.

  2.  Structure is introduced for dealing with integer, character and float variable in a same name.

  3. Structure is a user defined data type.

  4. Structure is declared using keyword "struct".

  5. SYNTAX :
        
        struct struct_name
         {
         
         data_type variable_name;
         data_type variable_name;
         ....
         data_type variable_name;
         
         };//This semicolon is compulsory.
    
    
        
        


UNION :


  1. Union is similar to structure in that they also store different types of elements.

  2. Union is similar to Structure. Syntax of both are same but major difference between structure and union is 'memory storage'.

  3. In structures, each member has its own storage location, whereas allthe members of union use the same location.

  4. Union also contains manymembers of different types but Union can handle only one member at a time.

  5. SYNTAX :
        
        union union_name
         {
         
         data_type variable_name;
         data_type variable_name;
         ....
         data_type variable_name;
         
         };//This semicolon is compulsory.
    
    
        
        

Comments