by Dinesh Thakur Category: Array Pointer and Union

Both the structures and unions are syntactically and functionally same, however, they differ in the way memory is allocated to their members. While declaring structure variables, the different members are stored in different, although, adjacent memory locations whereas different members of a union variable share the same memory location. The amount of memory sufficient to hold the largest member of a union is allocated to a union variable. Thus, a union enables the same block of memory to store variable of one type at one time and of different type at another time. To understand the concept of memory allocation to a union, consider these statements.

 
by Dinesh Thakur Category: Array Pointer and Union

Like arrays, structures are also used to store a list of data items in a single variable. However, these data items may be of different data types. Structures are used whenever a programmer requires binding the same or different types of related data items together into a single entity.



 
by Dinesh Thakur Category: Array Pointer and Union

Arrays are declared as follows:

 

int p[5];

float temp[30];

char a[7];

 
by Dinesh Thakur Category: Array Pointer and Union

When an element of a structure has to be accessed through pointer, then the -> operator is used. It is essential to initialize the pointer before it accesses any structure element.

 

Page 3 of 4



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles