What is the output of the following C program on a 64-bit system?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *p = malloc(10 * sizeof *p);
if (p == NULL)
return 1;
printf("%zu %zu\n", sizeof p, sizeof *p);
free(p);
return 0;
}
sizeof p is the size of the pointer variable (8 bytes); sizeof *p is one int (4). Nothing in C remembers that the block holds 40 bytes – you must keep the count yourself.