使用函數(shù)更改指針包含的地址如果我聲明了一個(gè)指針p如int *p;在主模塊中,我可以更改p通過(guò)分配p=&a;哪里a是另一個(gè)已聲明的整數(shù)變量。我現(xiàn)在想通過(guò)使用如下函數(shù)來(lái)更改地址:void change_adrs(int*q){
int *newad;
q=newad;}如果我從主模塊調(diào)用這個(gè)函數(shù)int main(){
int *p;
int a=0;
p=&a; // this changes the address contained by pointer p
printf("\n The address is %u ",p);
change_adrs(p);
printf("\n the address is %u ",p); // but this doesn't change the address
return 0;}地址內(nèi)容不變。在相同的任務(wù)中使用函數(shù)有什么問(wèn)題?
使用函數(shù)更改指針包含的地址
胡說(shuō)叔叔
2019-07-03 10:11:00