/*In the following program i have to find the size of structure cal without making use of sizeof Operator but is incomplete, so add minimum line of  code accomplish this*/

//note :-do not make use of sizeof

#include<stdio.h>

struct cal

{

 long double d;

 float f;

 char c;

};

void main()

{

 int i;/*add code to find size*/;

 printf("the size of cal is %d",i);

}

<< moderator edit: added [co[u][/u]de][/co[u][/u]de] tags >>


can anyone tell me the solution for this problem

If you had an array of at least two of the objects, and you took the address of adjacent elements, cast each address to a char* , and found the difference between each address, you would have the size of one object.

Hi Dave....i was able to solve this problem the way you told by taking two objects...but i was trying to solve it through single object....i took two char pointers as you said and made it point to the individual members of the structure....i tried to find successive differences but got stuck with last element.....is there any way to solve it....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.