Hi
I have the following MWE:
What I don't understand is that new_ptr and old_ptr have the same address in my program? That is what printf shows.. I thought new_ptr would point to a new memory block. Where am I wrong here?Code:#include <stdio.h> #include <stdlib.h> int main() { int *old_ptr = malloc(sizeof(int)); // ALLOCATE ARRAY old_ptr[0] = 0; // ASSIGN A VALUE int *new_ptr = realloc(old_ptr, 2*sizeof(int)); // CREATE A NEW ARRARY new_ptr, WHICH HAS TWICE THE SIZE OF old_ptr printf("%d\n%d\n\n", old_ptr, new_ptr); // THEY HAVE THE SAME ADDRESS?! printf("%d", new_ptr[0]); // THEY HAVE THE SAME ADDRESS?! return 0; }