Computer Science, asked by yashwanth6555, 11 months ago

difference between structure and union ​

Answers

Answered by anjali1063
2

Answer:

             STRUCTURE

  • The separate memory location is allotted to each member of the 'structure'.                
  • struct struct_name{

         type element1;

         type element2;

         .

         .

         } variable1, variable2, ...;

  • 'struct'
  • Size of Structure= sum of size of all the data members.
  • Stores distinct values for all the members.
  • A 'structure' stores multiple values, of the different members, of the 'structure'.
  • Provide single way to view each memory location.
  • No Anonymous feature.

                                              union

  • All members of the 'union' share the same memory location.
  • union u_name{

        type element1;

       type element2;

        .

        .

       } variable1, variable2, ...;

  • 'union'
  • Size of Union=size of the largest members.
  • Stores same value for all the members.
  • A 'union' stores a single value at a time for all members.
  • Provide multiple way to to view same memory location.
  • Anonymous union can be declared.
Similar questions