Following is my code
#include <stdio.h>
#include <stdint.h>
union myUnion {
struct {
uint8_t a1;
uint8_t b1;
uint8_t c1;
uint8_t d1;
uint8_t e1;
} abc;
int a;
};
int main() {
printf("size:%ld\n", sizeof(union myUnion));
return 0;
}
Output:
size:8
Here why size of union is 8, stuct has 5 member total 5byte and int a 4byte hence size should be 9 correct, why size returns 8 ?
Trying to undersatand how memory allocation happend