then how other two structure members will get initialized without intitializing them exclusively?
They won't.
You'd be getting garbage values in ab->b
and ab->c
because i
does not represent a chunk of memory of a sufficient size to represent an instance of abc
.
ab->a
is equal to 0 because when you did: *i = 0
, you stored the value 0
in the memory location that i
pointed to. When you made abc
point to the same memory location as i
, no writes were done to memory, you just changed the position of the data.
Since 0
was previously stored in 4 bytes at the position that i
pointed to, and since int ab::a
happens to take up 4 bytes and also happens to be the first member of the struct, ab->a
will be equal to 0.
In memory, relative to the position of the instance, your struct is ordered like this:
____ ____ ____ ____ ____ ____ ____ ____ ____
| 00 | 01 | 02 | 03 | | 04 | | 05 | 06 | 07 | 08 |
|____|____|____|____| |____| |____|____|____|____|
int a char b float c
I hope this clears things up.
Note
You're not really guaranteed to have the struct completely packed up like I made it seem in the above representation. While order will be conserved, the space between consecutive members is not always going to be 0 memory address units. Read up on Alignment.