Compare and contrast between structure and union in C. [WBUT MCA 2011]
Both structure and union are the ADT or Abstract Data Type in C which are bind the one or more different types of data variables within a scope. Those variables are accessed by the corresponding structure or union variables. But there is a simple difference between them.
Structure can use all the variables within it. I.e. it can store or access the said variables in it at a time. Structure allocates separate memory for each of the variables declared in it. It allocates more memory than union. We declared a structure using the keyword “struct”.
But in union only one variable of any type can access at a time. It occupies a smaller memory space than a structure. It occupies the same quantity of memory which occupies the largest variable, declared within it. To declare a union, we use the keyword “union”.