What is the difference between struct and union?



Suraj Said

+0 -0

structs are used to group multiple variables of different types together under a single name, each variable has its own memory space.
Unions on the other hand, share a memory space among all of its members, so only one member can be accessed at a time.
Structs are typically used to represent complex data structures, while unions are used when memory space is a concern and only one of the values of different types is needed at a time.



Submit Your Response