I get this code over my pass year question
therefore there is a question that i do not understand
why the output is 3??For "numbers[0]"
there is no "&" in the void function, so under my thought, the value of y[0] should not be sent over back to the main function
Arrays are a bit special. When you pass an array like this you will actually be passing a pointer to the first element in the array. line 28 could have been written void m(int x,int* y) to better show what's going on.
Thanks for the reply Peter!
so I can deduce that, the elements in the array y is equal to the element in the array numbers ??
Erm...
for the pointer that part ,
do array y point to array numbers ??
so as we change the value in array y, it will eventually change the value in array numbers?
int Array[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int * ArrayPointer = Array;
Now let's take a deep look at ArrayPointer:
Array = (Address of Memory where Data is stored at, let's say 0x01010101)
ArrayPointer = Array = 0x01010101
ArrayPointer[0] = (First element found at 0x01010101 in memory)
ArrayPointer[0] = Array[0] = *ArrayPointer = *Array = 1 (See over why 1)
ArrayPointer[1] = Array[1] = *(ArrayPointer+1) = *(Array+1) = 2
etc etc...