C and Sizeof question..

Steve Jardine sjardine at acm.org
Wed Nov 12 11:33:20 PST 2008


Calling all C Gurus!!

Consider this C code:

#include <stdio.h>
main() {

typedef struct {
char           name[256];
char           type[1]; 
int             size;
}resp;

char n[256];
char t[1];

printf("sizeof resp is %d\n",sizeof(resp));
printf("sizeof int is %d\n",sizeof(int));
printf("Total: %d\n", sizeof(int)+sizeof(n)+sizeof(t));
}

Can anyone explain why the sizeof the struct is 264 bytes, yet adding up all of its components yields 261 bytes?
Call me confused...

TIA...

Steve



More information about the Linux-users mailing list