30 likes | 162 Views
Unions. Defining , Initializing, and Using. Unions. Unions are similar to structures are made up of different types of elements, but unlike structures, all elements point to the same memory location. The amount of memory allocated for a union is the longest element inside the union. Unions.
E N D
Unions Defining , Initializing, and Using
Unions • Unions are similar to structures are made up of different types of elements, but unlike structures, all elements point to the same memory location. • The amount of memory allocated for a union is the longest element inside the union. CENG 114
Unions • Defining a union: union grade { int a; /* 4 bytes */ double b; /* 8 bytes */ } b a 6.24 5 x.a = 5; x.b = 6.24; x CENG 114