[英]What is the meaning of changing char pointer to int pointer
I have the following code from previous exam in c:我在 c 中的先前考试中有以下代码:
int main(int argc, char **argv) {
char s[] = "123";
int* a = (int*) s;
printf(("%x"),*a);
return 0;
}
The output is: 333231
output为:
333231
My question is why?我的问题是为什么? how does changing the pointer effect it?
更改指针如何影响它?
You don't have to declare a separate variable.您不必声明单独的变量。 This would do:
这会做:
printf(("%x"),(int*)s);
The pointer type dictates how the pointee is interpreted when the pointer is dereferenced.指针类型决定了指针被取消引用时如何解释指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.