P
pete
kris said:Hi I am writing a small program where I need to obtain the actual size
of a structure.
The programm is as follows
struct abc
{
int j;
char k;
int i;
}*a;
main()
{
a->j=10;
printf("size of structure is %d",sizeof(a));
}
In this program when I print the size of structure I get the whole
size (i.e size of 2 int variables+size of char variable).
But I need to get the size of structure such that it resembles the
chunk of memory that is actually being used.
/* BEGIN new.c */
#include <stdio.h>
struct abc {
int j;
char k;
int i;
} *a;
int main(void)
{
printf("size of structure is %u.\n",
(unsigned)sizeof (struct abc));
printf("size of structure is %d.\n",
(int)((char *)(a + 1) - (char *)a));
return 0;
}
/* END new.c */