Why is there a gap between 1 and 2?
The start address of the structure is always equal to the address of its first member. From standard C:
6.7.2.1-13. A pointer to a structure object, appropriately transformed, points to its initial member
The first member is not age , but name . Thus, the following two lines should print the same address:
printf("1. Address of joe \t= %x\n", joe); printf("1. Address of name-pointer \t= %x\n", &joe->name);
In your code
printf("5. Address of name \t= %x\n", joe->name);
does not print the address of the pointer, but the address of the data pointed to by the pointer.
How is the size * of the name calculated since the name only points to the first char?
name is a pointer that takes up 8 bytes of memory regardless of the size of the data it points to (it could be a string, as in your case, one char, int, or something else).
Why is there a gap between 4 and 5?
The memory for storing the actual name string is not part of the structure - strdup allocates memory somewhere to duplicate the string. This will be 16 bytes after the last member of your structure. This memory location indicates your name pointer.
Note that filling and aligning the memory is a factor only for the size of the structure (they do not matter for your explicitly asked questions). Since the structure contains one pointer (8 bytes on your computer) and 3 integers (4 bytes each), we can assume that the total size is 20 bytes. On most platforms, 8 bytes are aligned β so your structure is rounded to 24 bytes. Thus, if you declare an array from Person s, each element of the array begins with an address that is aligned by 8 bytes, i.e. The address value can be evenly divided by 8.