[問題] 指標變數的小問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
下列程式碼中,i的值分配給*pi
那為何在輸出的時候,cout<<pi的值不是&i的值?
而下面是我所知的正確作法 pi=&i 就沒有這個問題
那麼在上段程式碼中,指標變數pi裡面存的是什麼?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<iostream>
using namespace std;
int main()
{
int i,*pi;
i = 1;
*pi = i;
cout<<pi<<endl;
cout<<&pi<<endl;
cout<<&i<<endl;
pi = &i;
cout<<pi<<endl;
cout<<&i<<endl;
system("pause");
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.192
→
06/15 17:58, , 1F
06/15 17:58, 1F
→
06/15 18:16, , 2F
06/15 18:16, 2F
→
06/15 19:38, , 3F
06/15 19:38, 3F
→
06/15 22:33, , 4F
06/15 22:33, 4F
→
06/15 22:36, , 5F
06/15 22:36, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章