Monday 27 January 2014

Structures Vs Unions

Structure                                       Union

(1) Each member has its own storage    All the members use the same location.
      location
(2) Structure can be declared using the          Union can be declared using the
      keyword struct                                                keyword union
(3) Members of structures can be read     Members of unions cannot be
     with the help of single ‘scanf’                     read all at once with the help
     statement.                                                 of single ‘scanf’ statement.
(4) struct tag-name                                       union tag-name
          {                                                {
                 Data-type member1;                       Data-type member 1;
      Data-type member 2;              Data-type member 2;

      ……………………                          ………..
 };                                             };
5) Structure members can be initialized           Only first member of the union can be
     at the time of declaration                  initialized at the time of declaration
    struct st-record student1=                union item abc= {100};
                             {60,180.75};                

No comments:

Post a Comment