Structure and union are a form of encapsulating similar data elements.
Structure:
Whenever a structure is declared, then space equal to the total size of the elements defined inside the structure is allocated. Hence each individual element has its own memory space. Hence structures are commonly used when there is usage for more than one element declared inside the struct at a time.
Union:
Whenever an union is declared, then space equal to the size of the maximum element defined inside the union is allocated. Hence the individual elements share a common memory space. Hence union is commonly used when there is usage for only one element declared inside the union at a time.
Structure is a query that is used in language c++
Both usable.
Union Trained Ironworkers
The trade union structure is managed from the local levels and usually has a national council. Trade unions are large organisations who will have representatives at local levels.
union is similar to structure .The distinction is in terms of storage. In structure each member has it own storage location but in union all the members use the same location. It can handle only one member at a time. example. union u { int a; char b[4]; }; A union may contain structure(s) and a structure may contain union(s). A structure (or an union) may contain unnamed unions (and structures), a useful feature and worth getting to know. Example: typedef union MYUNION { . struct { . . int x; . . int y; . } int_coord; . struct { . . double x; . . double y; . } dbl_coord; } MYUNION; It's a fragment of memory shared by multiple variables.
chloroplasgt
European Community A+
European Community
Democratic union
European Community A+
union occupies a lesser memory space compared to structure as the same memory block is used for all the members in union
C unions are also like structures. We have to allocate more memory when we use stucture.Because, memory needs to be allocated to all structure variables. Where as in Union, less memory is enough to allocate. Because, memory is allocated for only one member which occupies more memory among all members in the union. But, both have their own advantages and disadvantages.I came across one website which gives fair idea of union and structure difference and good sample programs and good explanationsC unionC structure