小编Fat*_*ğlu的帖子

在C++或C中使用Integer和Char指针?

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)

c c++ pointers

-1
推荐指数
1
解决办法
139
查看次数

标签 统计

c ×1

c++ ×1

pointers ×1