Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
With a union you can switch between different data types but you can only assign one value to a union. So you dont have to allocate memory space for all elements. Instead you only allocate memory for the biggest data type in the union, so all data types of the elements in the union will fit in this memory location. In a struct you allocate memory for all declared variables.
31st May 2020, 8:00 PM
Jnn
Jnn - avatar