How do the two implementations differ:
struct queue {
int a;
int b;
q_info *array;
};
and
struct queue {
i
In the first one there is actually a pointer allocated in struct queue
, and sizeof(struct queue) == 2 * sizeof(int) + sizeof(q_info*)
In the second one there is no pointer or anything named array
really exists in struct queue
, and sizeof(struct queue) == 2 * sizeof(int)
. This is known as a trick to conveniently reference the data before or later using array
. I've used this trick in implementing a memory allocator.