字符指针 [英] character pointers
问题描述
可能重复:
字符指针
这不是'a'
被解码为其ascii代码值,并且以下语句变为等价于 char * pch = 197
。现在 pch
将指向地址位置197中的字符
pch ='a'; // if not then then this statement mean
在此行中,您将创建一个指向字符(char *)的指针,名称为'pch'。然后,您尝试将其初始化为字符'a' - 这是不可能的,因为指针只能使用某个对象的地址或空指针(0)初始化。
如果您想要设置pch变量指向地址197下的位置,可以尝试以下操作之一:
char * pch = char *)197;
char * pch = reinterpret_cast< char *>(197); // C ++ only
Possible Duplicate:
character pointers
Is it not that 'a'
is decoded to its ascii code value and the following statement becomes equivalent to char *pch= 197
. Now pch
will point to the char in address location 197
char *pch='a'; //if not then what does this statement mean
This line should not compile at all, at least in C++.
In this line, you create a pointer to character (char *) with name 'pch'. Then, you try to initialize it to character 'a' - that is not possible, because pointers can be initialized only with address of some object, or with null pointer (0).
I think that in C it is illegal too, but I'm not sure about it.
If you want to set up the pch variable to point to the location under the address 197, you can try one of the following:
char *pch = (char *) 197;
char *pch = reinterpret_cast<char*>( 197 ); // C++ only
这篇关于字符指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!