[英]character pointers
is it like char *pch='a';
就像
char *pch='a';
means pch holds value 97
and is a pointer to another char whereas char *pch="avinash";
表示pch保持值
97
并且是另一个char的指针,而char *pch="avinash";
means that pch
holds the pointer pointing to a of avinash. 表示
pch
持有指向avinash的指针。
char *pch='a';
shouldn't compile on any standard-compliant compiler. 不应在任何符合标准的编译器上进行编译。
char* pch = "absljsdf"
is deprecated. char* pch = "absljsdf"
已弃用。 you must use const
. 您必须使用
const
。
const char * pcch = "abdsfkjsdf";
means that pcch points to the first character in "abdsfkjdf", but you can't modify the contents of the string with that pointer. 表示pcch指向“ abdsfkjdf”中的第一个字符,但是您不能使用该指针修改字符串的内容。 hth
hth
char *pch="avinash"; char * pch =“ avinash”; is a string literal and what you said is right.
是字符串文字,您说的没错。 but the first one is a compile error.
但是第一个是编译错误。 did you try compiling them and seeing the values?
您是否尝试编译它们并查看值?
No. 没有。
char * pch='a';
means that the address of pch is the value of 'a' which most likely points to an invalid part of the memory :-). 表示pch的地址是'a'的值,该值很可能指向内存的无效部分:-)。 If you want to set pch to point to 'a' you need to first allocate memory and then set
如果要将pch设置为指向“ a”,则需要先分配内存,然后再设置
*pch = 'a';
for instance. 例如。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.