簡體   English   中英

以下與指針相關的代碼的 output 將是什么?

[英]what will be the output of the following code related to pointers?

對於以下代碼,屏幕上應該顯示什么?

int num = 125;
int *numPtr ; numPtr = #
cout << numPtr << ’\t ’ << *numPtr;

選項: A. memory 變量 numPtr 的地址,后接制表符,后接 125 B. memory 變量 num 的地址,后接制表符,后接 125 Z0D61F8370CAD1D412F5Z0B.48 num 的十六進制值,后跟制表符,后跟 125 D。

想一想:

您創建一個名為 num 的 int 值 125

int num = 125;

然后創建一個指針 numPtr(記住指針只是一個 memory 地址),它必須指向一個 int。

int *numPtr;

然后,您將 memory 地址 num (這就是地址運算符 ( & ) 的意思,“獲取 memory 地址”),並將其放入 numPtr 中,因此 numPtr 現在包含 num 的地址。

numPtr = &num;

如果您現在只有 output std::cout << numPtr您將獲得 memory 地址,並在您鍵入*numPtr的位置獲取值

有了這些信息,我認為您應該能夠了解正在發生的事情。 祝你考試順利。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM