gpt4 book ai didi

C++ 将 char 指针设置为 null

转载 作者:太空狗 更新时间:2023-10-29 20:04:48 25 4
gpt4 key购买 nike

<分区>

在 Visual Studio 2012 中,我正在摆弄指针,我意识到这个程序一直在崩溃:

#include <iostream>
using std::cout;
using std::endl;

int main ()
{
const char* pointer = nullptr;

cout << "This is the value of pointer " << pointer << "." << endl;

return 0;
}

我的意图是设置一个指向nullptr指针,然后打印地址。即使程序可以编译,它也会在运行时崩溃。谁能解释一下这是怎么回事?

还有,pointer*pointer 有什么区别?

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