struct ptr
{
int a;
char b;
int *p;
}abc;
what is d sizeof structure without using "sizeof" operator??
Answer Posted / pradeep
In Linux, its 12 bytes.
int a ------- 4 bytes
char b ------- 1 byte.
but as the next element is integer, it wont fit in the
remaining 3 bytes left after the "char b" occupies the first byte of the 4 byte chunk. so these 3 bytes wont be used for storing "int *p". these will be padded. next 4 bytes will be used for storing *p.
to prove it.
int size;
size = (&(abc.p) + sizeof(abc.p)) - &abc.a ;
printf("size = %d",size);
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are the storage classes in C?
What is wrong with this program statement?
What kind of structure is a house?
What is the purpose of scanf() and printf() functions?
Explain the use of bit fieild.
What is bubble sort technique in c?
What is maximum size of array in c?
Is array a primitive data type in c?
How is actual parameter different from the formal parameter?
If fflush wont work, what can I use to flush input?
Why can’t we compare structures?
Is it better to use malloc() or calloc()?
Why isnt any of this standardized in c?
What is sizeof array?
What is the difference between #include