什麼是錯的在於:我只是想指針爲int,並給出0指針在C++詮釋
int* p;int* q;
*p = 0; *q = 0;
cout<<"p = "<<*p<<" q = "<<*q<<endl;
是整型值。這是煩人
WORKS:
int* p;
*p = 0;
cout<<*p<<endl;
崩潰:
int* p;
int* q;
*p = 0;
*q = 0;
cout<<*p<<endl;
參見:http://en.wikipedia.org/wiki/Dangling_pointer#Cause_of_wild_pointers –
複製(相同的用戶):如何獲得在C++整數的動態分配的數組的大小](HTTP:// stackoverflow.com/questions/12196712/how-to-get-size-of-a-dynamic-allocated-array-of-ints-in-c) –
@PaulR這是**不**相同的問題! –