Structure and union are two data types used in C programming language. Both have their own characteristics, advantages and disadvantages. This article explains the differences between structure and union with examples to help better understand them.
About Difference Between Structure And Union
Structure | Union |
---|---|
Holds multiple data types in separate memory locations | All members of a union share the same memory location |
Each member has its own storage space | Only one member can be used at a time |
Size depends on the total size of all members | Size is equal to the largest member |
Accessible by individual names | Accessible only through a single name |
More secure than unions | Less secure than structures |
Can have methods/functions | Cannot have functions or methods |
— by
Leave a Reply