Q5. Find the size of structure without using sizeof() operator.

To find size of a structure.  We can use a pointer as we know if we increment structure pointer by one it will incremented by size of that structure, see below.

struct find_size{

int num;

char chr;

};

int main()

{

int size_of_structure = 0;

struct find_size *a = 0;

size_of_structure = ((char *)(a + 1)) – ((char *)a);

printf(“size_of_structure = %d\n”,size_of_structure);

return 0;

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.