answersLogoWhite

0

Why do you go for structure and union?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

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.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why do you go for structure and union?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is structure and union?

Structure is a query that is used in language c++


Structure and union in c?

Both usable.


Who built the steel structure?

Union Trained Ironworkers


Trade union structure?

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.


What is anonymous union in c?

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.


What structure is found in elodea and not in potato and union cells?

chloroplasgt


What is the legal structure of the Economic Union for community policies?

European Community A+


is the legal structure of the Economic Union for community policies?

European Community


The structure of the US Congress was created at the Constitutional Convention by the?

Democratic union


What is the legal structure of economic union of the community policies?

European Community A+


What are the advantages of union over structures?

union occupies a lesser memory space compared to structure as the same memory block is used for all the members in union


How do you Declare and initialized structure list different between union and structure?

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