C - Structure and Union Question & Answer
Structure and Union Question Answer
Question : What is a structure?
Answer : Structure constitutes a super data type which represents several different data types in a single unit. A structure can be initialized if it is static or global.
Question : What is a union?
Answer : Union is a collection of heterogeneous data type but it uses efficient memory utilization technique by allocating enough memory to hold the largest member. Here a single area of memory contains values of different types at different time. A union can never be initialized.
Question : What the advantages of using Unions?
Answer : When the C compiler is allocating memory for unions it will always reserve enough room
for the
largest member.
Question : What are the differences between structures and union?
Answer : A structure variable contains each of the named members, and its size is large enough to hold all the members. Structure elements are of same size. A union contains one of the named members at a given time and is large enough to hold the largest member. Union element can be of different sizes.
Question : What are the differences between structures and arrays?
Answer :Structure is a collection of heterogeneous data type but array is a collection of homogeneous data types.
Array
1-It is a collection of data items of same data type.
2-It has declaration only
3-.There is no keyword.
4- array name represent the address of the starting element.
Structure
1-It is a collection of data items of different data type.
2- It has declaration and definition
3- keyword struct is used
4-Structure name is known as tag it is the short hand notation of the declaration