What is the difference between struct and union in C?

Answer Posted / hrpynux@gmail.com

A struct is a block of memory that stores several data objects, where those objects don't overlap. A union is a block of memory that stores several data objects, but has only storage for the largest of these, and thus can only store one of the data objects at any one time.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?

796


What is the benefit of using an enum rather than a #define constant?

921


Why static is used in c?

821


What is the use of function in c?

914


Why do we use int main instead of void main in c?

888


Where are c variables stored in memory?

792


What is masking?

893


Explain data types & how many data types supported by c?

815


What is an array in c?

774


What is calloc() function?

851


What’s a signal? Explain what do I use signals for?

838


What are c header files?

773


How can I handle floating-point exceptions gracefully?

867


How can I list all of the predefined identifiers?

754


How can I get random integers in a certain range?

780