I received, among others, the following two questions at some tests here at my university, but I’m not sure about the right answers. The questions are for the C language, not C++.
Q1 Assuming that addresses are represented on 4 bytes, how much memory space is reserved by the following declarations:
Remember that extern just tells the compiler that something already exists elsewhere.
Also remember that a type declaration doesn't actually reserve any memory -- all it does is tell the compiler how to organize (or view) some piece of memory.
The only time memory is reserved is when actually declaring variables.
For Q1, extern takes 0 bytes and struct also 0 bytes, so right answer A 0 bytes.
For Q2, extern takes 0 bytes, but struct, being declared there as val, takes 4 bytes for the long variable and 4 bytes for the pointer to struct variable, so right answer C 8 bytes.
If I answered correctly that means that I got it. :D
Thanks once again!
And last but not least, I liked the way you managed to reply, you didn't provided me directly the answers, but guided me and let me think about which ones are correct.