所以char a [] =&QUOT之间的差异;串英寸;的char * p ="串英寸; [英] Difference between char a[]="string"; char *p="string";
问题描述
可能显示的文件:结果
<一href=\"http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c\">What是个char []和char * S用C?
什么是之间的差异char的一个[] =串;
和的char * p =串;
?
推荐答案
第一种是阵列另一种是指针。
The first one is array the other is pointer.
数组声明烧焦一个[6];
是6个字符的空间预留,由名为被称为请求一。
也就是说,有一个名为位置 A
在这六个字符可以坐。该指针声明的char * p;
,另一方面,要求持有一个指针的地方。指针是由名为 P,
,可以指向任何字符(字符或连续的数组)的任何地方。
The array declaration "char a[6];
" requests that space for six characters be set aside, to be known by the name "a.
" That is, there is a location named "a
" at which six characters can sit. The pointer declaration "char *p;
" on the other hand, requests a place which holds a pointer. The pointer is to be known by the name "p,
" and can point to any char (or contiguous array of chars) anywhere.
中的语句
char a[] = "hello";
char *p = "world";
将导致可能被重新psented这样的$ P $的数据结构:
would result in data structures which could be represented like this:
+---+---+---+---+---+---+
a: | h | e | l | l | o |\0 |
+---+---+---+---+---+---+
+-----+ +---+---+---+---+---+---+
p: | *======> | w | o | r | l | d |\0 |
+-----+ +---+---+---+---+---+---+
认识到,如x一个参考文献[3]产生不同code取决于x是否数组或指针是很重要的。鉴于上述声明,当编译器看到前pression一个[3],它发出code,开始在位置A移动过去三个吧,这里面提取的字符。当看到前pression P [3],它发出code的位置开始P,取指针值出现,添加三个指针,最后取字符指出。在上面的例子中,两个一[3]和p [3]碰巧是字符L,但是编译器到达那里不同。
It is important to realize that a reference like x[3] generates different code depending on whether x is an array or a pointer. Given the declarations above, when the compiler sees the expression a[3], it emits code to start at the location "a," move three past it, and fetch the character there. When it sees the expression p[3], it emits code to start at the location "p," fetch the pointer value there, add three to the pointer, and finally fetch the character pointed to. In the example above, both a[3] and p[3] happen to be the character 'l', but the compiler gets there differently.
您可以使用搜索有吨在互联网届的主题解释。
You can use search there are tons of explanations on the subject in th internet.
这篇关于所以char a [] =&QUOT之间的差异;串英寸;的char * p =&QUOT;串英寸;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!