-
Perverted
Little more help for ME
Yes I have one more question for the great people at the C board.
What I am wonder ing is in the code below hoe does the function change() multiply *pnumber by 2 if *pnumber is not given a value in that function and is not globally declared?
#include <stdio.h>
int change(int* pnumber);
void main()
{
int number = 10;
int* pnumber = &number;
int result = 0;
result = change(pnumber);
printf("\n In main, result = %d\t number = %d", result, number);
}
int change(int* pnumber)
{
*pnumber *= 2;
printf("\n In function change, *pnumber = %d", *pnumber);
return *pnumber;
}
-
pnumber is passed to the function change()
result = change(pnumber);
therefore the value that pnumber points to can be multiplied by 2 in change() because change() has a copy of the pointer.
Hope that makes sense,
(: Ian
-
of Zen Hall
Because you've passed the address into the function. A copy of this address is used within the function, but as the pointer has been de-referenced you're multiplying the value stored at this address.
Popular pages
Recent additions