S.N | Structure | S.N | Union |
1. | You can use a struct keyword to define a structure. | 1. | You can use a union keyword to define a union. |
2. | Every member within structure is assigned a unique memory location. | 2. | In union, a memory location is shared by all the data members. |
3. | Changing the value of one data member will not affect other data members in structure. | 3. | Changing the value of one data member will change the value of other data members in union. |
4. | The total size of the structure is the sum of the size of every data member. | 4. | The total size of the union is the size of the largest data member. |
5. | It occupies space for each and every member written in inner parameters. | 5. | It occupies space for a member having the highest size written in inner parameters. |
6. | You can retrieve any member at a time. | 6. | You can access one member at a time in the union. |