I have my code here:
int main(){
printf("%lu\n",(1 * sizeof(int)));
int* hello=malloc(1 * sizeof(int));
hello[1000000]=10;
printf("%d \n",hello[1000000]);
printf("%lu \n", sizeof(hello));
int* goodbye=malloc(100 * sizeof(int));
printf("%lu \n",sizeof(goodbye));
hello=goodbye;
printf("%lu \n",sizeof(hello));
hello=realloc(hello,20);
hello[1]=0;
printf("%lu \n",sizeof(hello));
}
It outputs this:
4 10 8 8 8 8
This throws has no warnings or errors, which is strange to me because I allocate only 4 bytes for the array hello, but can access hello[1000000].
Also, I tried to resize hello with goodbye, but the size stays the same. At line 10, I do hello=goodbye; which should resize it? I'm a little new to c memory stuff. Realloc also does not change the size of my array. I am trying to make "hello" be a dynamically sized array. What am I doing wrong here?
The code is supposed to be barebones reallocating memory and changing the size of an int array.