1 / 5

UNION

UNION. popo. Union. Union is same as the structure Like structure, union also contains members of different data type Union can be declared using the keyword union Syntax: union unionname { member 1; member 2; . . . .

anana
Download Presentation

UNION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNION popo

  2. Union • Union is same as the structure • Like structure, union also contains members of different data type • Union can be declared using the keyword union • Syntax: union unionname{ • member 1; • member 2; • . . . . • }; • Like structure a union variable can be declare • Syn: union unionname variable list; • popo

  3. Union and Structure • The memory space occupy for a union variable is the size of largest member • In structure each members has its own memory locations • In union all members shares a common memory location • In structure we can access all members at a time • In union we can access only one member at a time • popo

  4. Union and Structure • Eg • Stuct check • { int age; char name[5]; • }s; • The memory space of struct variable s=sum of size of all members • Iesizeof(age)+sizeof(name) • => 2+5 = 7 bytes • The structure variable has separate memory locations for each members • Can access all members at a time • popo

  5. Union and Structure • Eg • union check • { int age; char name[5]; • }u; • The memory space of union variable s=size of largest members • Iesizeof(name) • => 5 = 5 bytes • The union variable has only one memory locations for all members • Can access only one member at a time • popo

More Related