1

let say I have a program like this,

typedef struct
{
    float hello;
} tData;

int main()
{
    printf("%d", sizeof(tData));
}

The value is 4, as the float is 4 bytes. It showed as expected.

However, when I add a new variable,

typedef struct
{
    uint8_t bool1:1;
    float hello;
} tData;

int main()
{
    printf("%d", sizeof(tData));
}

I thought that it should display 5, but I got 8. May I know why?

Jimmy Kueh
  • 15
  • 6
  • 2
    This is a dupe, but still: don't print `size_t`-type values using `%d`, you must use `%zu`. – unwind Mar 17 '20 at 09:46

0 Answers0