Answers/Solutions to Exercises in Chapter 3, Exercise 5

E5: Calculate the size in bytes of the following structure:
struct {
    int b;
    char a;
    int c;
}

A5:  If you complained that it was not a proper question, you were right. The size of the structure depends on several factors: the sizes of int and char and, of course, the actual gist of the question: the padding. So, under the usual 32-bit platform and the usual C or C++ compiler that pads according to word bounderies, the size will be 12 bytes: 4 bytes for b, 1 byte for a, 3 bytes of padding, and 4 bytes for c.

Back to Answers/Solutions Index                          Back to Answers/Solutions for Chapter 3 Index