简体   繁体   English

(char*) 在 c 中是什么意思?

[英]What does (char*) mean in c?

What does char*ptr=(char*)&i; char*ptr=(char*)&i;是什么意思char*ptr=(char*)&i; exactly do in the following code完全按照下面的代码做

#include <stdio.h>
 int main()
 {
  int i=32;
  char*ptr=(char*)&i;
  printf("%d",*ptr);
  return 0;
 }
char* ptr=(char*)&i;

i is of type int . iint类型。 So you are trying to cast address of i as a character pointer and assign it to a local variable called ptr .因此,您试图将i地址转换为字符指针并将其分配给名为ptr的局部变量。 This way each byte stored in i can be read.这样可以读取存储在i每个字节。 Read more on pointers to understand in detail.阅读有关指针的更多信息以详细了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM