If I've declared a pointer p
as int *p
; in main module, I can change the address contained by p
by assigning p=&a;
where a
is another integer variable already declared.
I now want to change the address by using a function as::
void change_adrs(int*q)
{
int *newad;
q=newad;
}
If I call this function from main module
int main()
{
int *p;
int a=0;
p=&a; // this changes the address contained by pointer p
printf("
The address is %u ",p);
change_adrs(p);
printf("
the address is %u ",p); // but this doesn't change the address
return 0;
}
the address content is unchanged. What's wrong with using a function for same task?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…