Ç - 之间的差异与QUOT; VAR的char []"和"字符* VAR"? [英] C - Difference between "char var[]" and "char *var"?
本文介绍了Ç - 之间的差异与QUOT; VAR的char []"和"字符* VAR"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待这两个向量之后在RAM同样进行再presentation:
I am expecting that both following vectors have the same representation in RAM:
char a_var[] = "XXX\x00";
char *p_var = "XXX";
但奇怪的,以类型的库函数 F(char参数[])
crushs如果我把它用 F中的运行的应用程序(p_var)
。但是,使用 F(a_var)
就OK!
But strange, a call to a library function of type f(char argument[])
crushs the running application if I call it using f(p_var)
. But using f(a_var)
is Ok!
为什么?
推荐答案
首先创建一个包含字符串的字符数组。的数组的内容可以修改。第二个创建一个字符指针,它指向一个字符串。字符串常量不能修改。
The first creates an array of char containing the string. The contents of the array can be modified. The second creates a character pointer which points to a string literal. String literals cannot be modified.
这篇关于Ç - 之间的差异与QUOT; VAR的char []"和"字符* VAR"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文