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


Please Help Members By Posting Answers For Below Questions

What is a header file?

830


What are pointers? Why are they used?

849


Why c is a mother language?

738


Which is better malloc or calloc?

858


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

1581


What are reserved words with a programming language?

828


What is const and volatile in c?

783


What is a double c?

773


What is dynamic memory allocation?

1046


What is the difference between int main and void main in c?

822


C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

806


What is dangling pointer in c?

809


What is meant by type specifiers?

877


What is the use of typedef in c?

784


Explain about C function prototype?

816