gpt4 book ai didi

c++ - 空指针异常(int Vs char)

转载 作者:行者123 更新时间:2023-11-30 02:31:46 26 4
gpt4 key购买 nike

<分区>

程序 1:

#include <iostream>
using namespace std;
int main ()
{
int *ptr = NULL;
cout << "The value of ptr is " << ptr ;
return 0;
}

程序 2:

#include <iostream>
using namespace std;
int main ()
{
char *ptr = NULL;
cout << "The value of ptr is " << ptr ;
return 0;
}

问题是,在程序 1 中,输出稳定为:

  The value of ptr is 00000000

而在程序 2 中,我使用了 char 指针而不是 int 指针,它给了我一个异常。

谁能帮我理解一下?

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