我是自学指针,想知道传递地址的正确方法是什么?从int *到int的转换无效
int main(){
int kevin = 10,tiu,gana;
int *kevinpointer;
kevinpointer = &kevin;
tiu = kevin;
gana = &tiu;
cout << "The value of Kevin is: ";
cout << kevin << endl;
cout << "The address of Kevin is: ";
cout << kevinpointer << endl;
cout << "The address of KevinPointer is: ";
cout << *kevinpointer << endl;
cout << "The value/address of tiu is: ";
cout << tiu << endl;
cout<< "The address of gana is: ";
cout << gana << endl;
}
我得到一个错误的 “加纳= &tiu;”> INT *的转换无效为int [F-许可。
在你的代码片段中,'gana'是一个'int',而不是指向'int'的指针,因此你不能在不触发警告的情况下为它分配一个地址'&tiu'。 – 2014-08-29 14:55:32
感谢您的回应!非常感激。 – 2014-08-29 14:56:30