..."字符*海峡=&QUOT之间的差异;和char海峡[N] =" ..."? [英] Difference between char *str = "…" and char str[N] = "…"?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c\">What是个char []和char * S用C?结果之间的差异
指针和字符串href=\"http://stackoverflow.com/questions/4380090/question-about-pointers-and-strings-in-c\">问题
块引用>我读到C中的字符串和我很困惑。两种方式我可以申报的字符串:
的char *海峡=这是字符串;
焦炭STR2 [20] =这是字符串;两者有什么声明之间的区别?当
字符STR2 [20]
超过的char * str中preferred
?解决方案的char *海峡=这是字符串;
使字符串中的
常量数据部分(也称为.rdata)
数据不能被修改的program.This的。字符STR2 [20] =这是字符串;
在此类型声明的数据是preferably
存储在堆栈区
程序的,如果申报的的功能范围<内部/ code>和
数据部分
如果全局范围内
。这对数据进行修改声明。所以,如果你有一个必要的修改数据,然后使用第二种方法。
Possible Duplicate:
What is the difference between char s[] and char *s in C?
Question about pointers and strings in CI'm reading about the strings in C and I'm confused. I can "declare" strings in two ways:
char *str = "This is string"; char str2[20] = "This is string";
What is the difference between the two declarations? When would
char str2[20]
be preferred overchar *str
?解决方案char *str = "This is string";
Puts the string in the
constant data section (also known as .rdata)
of the program.This data can't be modified.char str2[20] = "This is string";
In this type of declaration data is preferably
stored in the stack area
of the program, if declared inside thefunction scope
and indata section
if declared inglobal scope
.This data can be modified.So if you have a necessity to modify data then use the second approach.
这篇关于...&QUOT;字符*海峡=&QUOT之间的差异;和char海峡[N] =&QUOT; ...&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!