How can we find size of a structure with out using sizeof operator?
Thanks,
Harika
How can we find size of a structure with out using sizeof operator?
Thanks,
Harika
one way to how they are allocated in memory:
typedef
struct
{
char a;
int b;
} mystruct_t;
int main()
{
mystruct_t arr[2]={0x0,0};
printf("%u %u\n", &arr[1], &arr[0]);
return 0;
}
The difference between the two addresses is how the individual structs are parked in memory.
I get
or 8 bytes, this is because both variables in the struct are word-aligned - ie on exact 4 byte boundaries.
another way...
#include <stdio.h>
main(void)
{
struct one
{
int a;
char b;
} x;
char dummy;
printf("size of struct one is %i bytes\n", (int) &(dummy) - (int) &(x.a));
}