How would you find the size of structure without using sizeof()?

Try using pointers
struct MyStruct
{
int i;
int j;
};

int main()
{
struct MyStruct *p=0;
int size = ((char*)(p+1))-((char*)p);
printf(“\nSIZE : [%d]\nSIZE : [%d]\n”, size);
return 0;
}

Advertisements

2 thoughts on “How would you find the size of structure without using sizeof()?

    1. Thanks for your valuable comment. Definitely i will use syntax highlighter forthcoming post and all my post as soon as possible…I will post lot questions in forthcoming day.Please check it out it might be useful…Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s