1
typedef struct{
    int tournamentNo;
    char tournamentName[61];
    char toutnamentDate[15];
    char tournamentCity[21];
}Tournament;

printf(" : %d ", sizeof(Tournament));

result: 104

actual: 61+15+21 + 4 = 101

typedef struct{
    int tournamentNo;
    char tournamentName[20];
    char toutnamentDate[15];
    char tournamentCity[21];
}Tournament;

printf(" : %d ", sizeof(Tournament));

result: 60

actual: 20 + 15 +21 +4 = 60

Why different this ?

Spikatrix
  • 20,225
  • 7
  • 37
  • 83
  • 1
    You have 3 additional padding bytes at the end of the struct, to maintain alignment (4 bytes in this case, presumably you're on a 32 bit OS). – Paul R Apr 02 '15 at 14:24
  • 1
    Similar question: http://stackoverflow.com/q/28928283/2455888 – haccks Apr 02 '15 at 14:25

0 Answers0