0

how to calculate the size of this structure:

struct Node{
    int data;
    char b;
    char *c;
};

when I run, it gives 16 bytes.

can anyone explain?

MikeCAT
  • 73,922
  • 11
  • 45
  • 70
satish s
  • 19
  • 1
  • *What* "gives 16 bytes"? Why does that result confuse you, i.e. what is your expectation and reasoning for it? What is your architecture and compile options? I'm guessing that on your system, an `int` is 4 bytes wide, but a pointer is 8 bytes wide. Then, 4 + 1 + 8 for the members, plus another 3 to ensure `*c` gets properly aligned by 8 bytes, equals 16. – underscore_d May 28 '21 at 12:48

1 Answers1

0

how to calculate the size of this structure.

You cannot calculate it by hand without knowing which language implementation will be used, because the language doesn's specify it. If you do know the language implementation, then you may find the information in the documentation of that language implementation. Specifically, you should be looking for information on the Application Binary Interface (ABI).

You can use the sizeof operator to get the size at compile time.

eerorika
  • 232,697
  • 12
  • 197
  • 326