C: Question on pointers
Hi!
I have a small test program that looks like this: Code:
void fill_arr(int *pointer, int size); Code:
Array value 0: 10 How can the address of the pointer 'pointer' be the same as array[0] AFTER I have added to it in the loop like this: Code:
pointer++; // move index by one to array[1], array[2], etc... Best, HMW |
well, this is merely a question of call-by-value or call-by-reference.
actually when you make the call Code:
fill_arr(pointer, SIZE); when it comes to Code:
void fill_arr(int *pointer, int size) For the sake of simplicity let's name the pointer in "fill_arr(pointer, SIZE);" as pointer1 and the pointer in "void fill_arr(int *pointer, int size)" as pointer2. so pointer2 is local to the function fill_arr. when you make the call to the function the value of pointer1 gets copied into pointer2. now this pointer2 is manipulated and not the pointer1. but in the main function it is still the pointer1 version. I hope you got it now. |
Quote:
Thanks! HMW |
All times are GMT -5. The time now is 07:16 AM. |