gpt4 book ai didi

c++ - 指针输出

转载 作者:太空宇宙 更新时间:2023-11-04 15:41:07 25 4
gpt4 key购买 nike

我只是想了解您输出指针的方式的不同。

假设我有:

int x = 100;
int*p = &x;

以下各项会做什么?

cout << p << endl;
cout << *p << endl;
cout << &p << endl;

最佳答案

cout << p << endl;  // prints the adress p points to,
// that is the address of x in memory
cout << *p << endl; // prints the value of object pointed to by p,
// that is the value of x
cout << &p << endl; // prints the address of the pointer itself

关于c++ - 指针输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com