Answer the Question

0
How to calculate size of any structure without using "sizeof" operator?
By : techie rich    On : 06-Dec-2012     Answers : 3      Report Abuse
Your Answer
Previous Answers
0
struct point {
char x;
int i;
float f;
char is;

}pt;

int main()
{
// struct point pt = {0},
struct point *ppt;
*ppt = &pt;
unsigned char *p1 = 0, *p2 = 0;

size_t size = 0;

p1 = (unsigned char*)(ppt);
p2 = (unsigned char*)(++ppt);
size = p2 - p1; // size is now 8 bytes (2 longs)
printf("%d\n",size);
// same as sizeof(struct point) or sizeof(pt)

return 0;
}
On : 10-Jan-2013   Accept Count : 0  
0
sizeof(struct);
On : 25-Dec-2012   Accept Count : 0  
0
struct point {
char x;
int i;
float f;
char is;

}pt;

int main()
{
// struct point pt = {0},
struct point *ppt;
*ppt = &pt;
unsigned char *p1 = 0, *p2 = 0;

size_t size = 0;

p1 = (unsigned char*)(ppt);
p2 = (unsigned char*)(++ppt);
size = p2 - p1; // size is now 8 bytes (2 longs)
printf("%d\n",size);
// same as sizeof(struct point) or sizeof(pt)

return 0;
}
On : 10-Dec-2012   Accept Count : 0  
By : ehete