#include <iostream> #include <string> using namespace std; void main() { //exp.4 char *charPtr=NULL; cout << "*charPtr = NULL" << endl; //cout << "*charPtr is : " << *charPtr << endl; //运行时错误:sizeof.exe 中的0x0041153b 处未处理的异常: 0xC0000005: 读取位置0x00000000 时发生访问冲突 //cout << "charPtr is : " << charPtr << endl; //运行时错误:sizeof.exe 中的0x0041153b 处未处理的异常: 0xC0000005: 读取位置0x00000000 时发生访问冲突 cout << "&charPtr is : " << &charPtr << endl; cout << "sizeof(charPtr) is : " << sizeof(charPtr) << endl; cout << "sizeof(*charPtr) is : " << sizeof(*charPtr) << endl << endl; //*charPtr = ""; //编译错误无法从“const char [1]”转换为“char” charPtr = ""; cout << "charPtr = \"\"" << endl; cout << "*charPtr is : " << *charPtr << endl; cout << "charPtr is : " << charPtr << endl; cout << "&charPtr is : " << &charPtr << endl; cout << "sizeof(charPtr) is : " << sizeof(charPtr) << endl; cout << "sizeof(*charPtr) is : " << sizeof(*charPtr) << endl << endl; charPtr = "a"; cout << "charPtr = \"a\"" << endl; cout << "*charPtr is : " << *charPtr << endl; cout << "charPtr is : " << charPtr << endl; cout << "&charPtr is : " << &charPtr << endl; cout << "sizeof(charPtr) is : " << sizeof(charPtr) << endl; cout << "sizeof(*charPtr) is : " << sizeof(*charPtr) << endl << endl; /* *charPtr = NULL &charPtr is : 0012FF60 sizeof(charPtr) is : 4 sizeof(*charPtr) is : 1 charPtr = "" *charPtr is : charPtr is : &charPtr is : 0012FF60 sizeof(charPtr) is : 4 sizeof(*charPtr) is : 1 charPtr = "a" *charPtr is : a charPtr is : a &charPtr is : 0012FF60 sizeof(charPtr) is : 4 sizeof(*charPtr) is : 1 请按任意键继续. . . */ }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)