[問題] 指標的練習問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
dev c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
指標產生的數字不是正確的
我複製範例的程式碼在我的電腦執行也一樣錯誤
餵入的資料(Input):
預期的正確結果(Expected Output):
變數n=11
指標np=n=11
t也是11喔
錯誤結果(Wrong Output):
變數n=11
指標np=n=2686788
t也是11喔
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
using namespace std;
int main(void){
//宣告整數變數n
int n=11;
printf("變數n=%d\n",n) ;
//宣告指標np
int *np = &n ;
printf("指標np=n=%d\n",np) ;
//宣告t
int t=*np;
printf("t也是%d喔\n",t);
system("pause");
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.249.92.60
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1424050633.A.40E.html
→
02/16 09:43, , 1F
02/16 09:43, 1F
推
02/16 11:02, , 2F
02/16 11:02, 2F
推
02/17 05:02, , 3F
02/17 05:02, 3F
推
02/17 05:05, , 4F
02/17 05:05, 4F
→
02/17 05:05, , 5F
02/17 05:05, 5F