int *ab = (int *)5656;
cout << *ab; //Here appcrash.
int *ab;
*ab = 5656;
cout << *ab; //These block crashes the app too.
Run Code Online (Sandbox Code Playgroud)
但是如果我写这个,我可以得到指针内容的十六进制值:
int *ab = (int *)5656;
cout << ab; //Output is hex value of 5656.
Run Code Online (Sandbox Code Playgroud)
所以我想问:*是一个带有指针(?)内容的运算符,但为什么在这个(这些)示例应用程序崩溃?
如果我将代码更改为此,我可以使用该运算符:
int a = 5656;
int *aptr = &a;
cout << *aptr; //No crash.
Run Code Online (Sandbox Code Playgroud)
为什么解除引用运算符(*)带来了char的唯一第一个字符:
char *cptr = "this is a test";
cout << *cptr; // Here output = 't'
cout << cptr; // Here output = 'this is a …Run Code Online (Sandbox Code Playgroud)