See the following function:
int go(void) {
int *p, *q;
p = calloc(10,sizeof(int));
q = realloc(p, 20 * sizeof(int));
<<X>>
}
Assuming that both memory allocation function calls are successful, which of the following statements are true at the point marker <<X>>.
- The values of p and q are the same.
- p points to 10 integers each with the value of 0.
- q points to at least 80 bytes of memory.
This question is in my C test paper. Except for (2) which is obviously true. I’m quite confused about (1) and (3). Can anybody explain me this?
As Brendan said, (1) is not necessarily true (and probably not true).
In C, generally an “int” is 4 bytes, so (3) should be true. It is true on all systems that I know of, although I’m not positive that the C standard says that an “int” must be four bytes long.