#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 4;
int *p = malloc(sizeof(int) * a);
int *g = malloc(sizeof(int) * a);
p += 8;
printf("%p\n", p);
printf("%p\n", g);
}
I have run this program several times, and every time the values of p and g printed at the end are the same. I'm not quite sure why this is happening - couldn't malloc theoretically pick anywhere in memory to have p and g point to? Why does p + 8 always equal g? Any clarification would be much appreciated.
Thanks!