What are the differences between a union and a structure in C? A union is a way of providing an alternate way of describing the same memory area. In this way, you could have a struct that contains a union, so that the “static”, or similar portion of the data is described first, and the portion that changes is described by the union. The idea of a union could be handled in a different way by having 2 different structs defined, and making a pointer to each kind of struct. The pointer to struct “a” could be assigned to the value of a buffer, and the pointer to struct “b” could be assigned to the same buffer, but now a->some field and b->some otherfield are both located in the same buffer. That is the idea behind a union. It gives different ways to break down the same buffer area. The difference between structure and union are: 1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory...
ALL ABOUT TECHNOLOGY,andthinker embedded tutorials and IOT tutorials ,interview questions