As I know, when a pointer is passed to a function, it becomes just a copy of the real pointer. Now I want to change the real pointer without returning the pointer from the function. For instance:
int *ptr; void allocateMemory(int *pointer) { pointer = malloc(sizeof(int)); } allocateMemory(ptr);
Another thing that is, how can I allocate memory for 2 or more dimensional arrays? Not by index, but by pointer arithmetic. It:
int array[2][3]; array[2][1] = 10;
same as:
int **array; *(*(array+2)+1) = 10
In addition, why do I need to pass the memory address of the function pointer, and not the pointer itself. For instance:
int * a;
why not:
allocateMemory(*a)
but
allocateMemory(a)
I know that I always need to do this, but I really donβt understand why. Please explain me.
Last, in a pointer like this:
int *a;
Is the memory address containing the actual value, or is the memory address of the pointer? I always think that this is the memory address of the actual value that it indicates, but I'm not sure about that. By the way, when printing such a pointer like this:
printf("Is this address of integer it is pointing to?%p\n",a); printf("Is this address of the pointer itself?%p\n",&a);
Amumu source share