Yukarıdaki örnekte görüldüğü gibi, union ve struct yapı arasında bellek ayırmada bir fark vardır. struct değişkenini depolamak için gereken bellek miktarı, tüm üyelerin bellek boyutunun toplamıdır. Ancak, bir union değişkenini depolamak için gereken bellek, union yapının en büyük öğesi için gereken bellektir.
Read moreWhich is better struct or union?
If you want to use same memory location for two or more members, union is the best for that . Unions are similar to the structure. Union variables are created in same manner as structure variables. The keyword “union” is used to define unions in C language.
Read moreWhat is the difference between a struct and a union?
A union is like a struct in that it generally has several fields, all of which are public by default. Unlike a struct, however, only one of the fields is used at any given time. In other words, it is a structure that allows the same storage space to be used to store values of different data types at different times.
Read moreWhich is better to use union or struct?
If you want to use same memory location for two or more members, union is the best for that . Unions are similar to the structure. Union variables are created in same manner as structure variables.
Read more