接下来的两个声明有什么区别? [英] what's the difference between the next 2 declarations?
问题描述
有什么区别:
char * x =" abcde" ;;
和
char y [] = {" abcde"};
我无法修改价值函数中的变量x,但是可以做y。
还有其他类似的问题需要注意吗?
提前致谢!
Wade Yin
Hi,
What''s the difference between:
char *x="abcde";
and
char y[]={"abcde"};
I can''t modify the value of the variable x in functions, but y can be do.
Is there any other similar problem need to be notice?
Thanks in advance!
Wade Yin
推荐答案
2004年4月5日星期一13:05:38 +0800, 韦德尹 < li ******** @ 163.com>
在comp.lang.c中写道:
On Mon, 5 Apr 2004 13:05:38 +0800, "Wade Yin" <li********@163.com>
wrote in comp.lang.c:
有什么区别:
char * x =" abcde" ;;
x是指向六个字符(包括''\ 0'')字符串的指针
literal。试图修改字符串文字会导致未定义的
行为。 x本身可以修改为指向不同的
字符数组。
和
char y [] = {" abcde"} ;
y是一个包含6个字符的数组,用字符串文字初始化。
y中的字符可以更改。
I不能在函数中修改变量x的值,但y可以这样做。
还有其他类似的问题需要注意吗?
不,字符串文字的情况是一种特殊情况,除了广泛的字符串文字外,还有其他类似的情况。
。
提前致谢!
Wade Yin
Hi,
What''s the difference between:
char *x="abcde";
x is a pointer to the a six character (including the ''\0'') string
literal. Attempting to modify a string literal causes undefined
behavior. x itself can be modified to point to a different array of
characters.
and
char y[]={"abcde"};
y is an array of 6 characters, initialized with the string literal.
The characters in y can be changed.
I can''t modify the value of the variable x in functions, but y can be do.
Is there any other similar problem need to be notice?
No, the situation with string literals is a special case and there are
no others like it, except for wide string literals.
Thanks in advance!
Wade Yin
-
Jack Klein
主页: http://JK-Technology.Com
常见问题解答
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c ++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
2004年4月5日星期一13:05:38 + 0800,Wade Yin < li ******** @ 163.com>
在comp.lang.c中写道:
On Mon, 5 Apr 2004 13:05:38 +0800, "Wade Yin" <li********@163.com>
wrote in comp.lang.c:
有什么区别:
char * x =" abcde" ;;
x是指向六个字符(包括''\ 0'')字符串的指针
literal。试图修改字符串文字会导致未定义的
行为。 x本身可以修改为指向不同的
字符数组。
和
char y [] = {" abcde"} ;
y是一个包含6个字符的数组,用字符串文字初始化。
y中的字符可以更改。
I不能在函数中修改变量x的值,但y可以这样做。
还有其他类似的问题需要注意吗?
不,字符串文字的情况是一种特殊情况,除了广泛的字符串文字外,还有其他类似的情况。
。
提前致谢!
Wade Yin
Hi,
What''s the difference between:
char *x="abcde";
x is a pointer to the a six character (including the ''\0'') string
literal. Attempting to modify a string literal causes undefined
behavior. x itself can be modified to point to a different array of
characters.
and
char y[]={"abcde"};
y is an array of 6 characters, initialized with the string literal.
The characters in y can be changed.
I can''t modify the value of the variable x in functions, but y can be do.
Is there any other similar problem need to be notice?
No, the situation with string literals is a special case and there are
no others like it, except for wide string literals.
Thanks in advance!
Wade Yin
-
Jack Klein
主页: http://JK-Technology.Com
常见问题解答
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c ++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
" Jack Klein" < ja ******* @ spamcop.net>
??????:1l ******************* *************@4ax.com。 ..
"Jack Klein" <ja*******@spamcop.net>
??????:1l********************************@4ax.com. ..
2004年4月5日星期一13:05:38 + 0800,Wade Yin < li ******** @ 163.com>
在comp.lang.c中写道:
On Mon, 5 Apr 2004 13:05:38 +0800, "Wade Yin" <li********@163.com>
wrote in comp.lang.c:
有什么区别:
char * x =" abcde" ;;
x是指向六个字符(包括''\0'')字符串的指针
字面意思。尝试修改字符串文字会导致未定义的行为。 x本身可以修改为指向不同的
字符数组。
Hi,
What''s the difference between:
char *x="abcde";
x is a pointer to the a six character (including the ''\0'') string
literal. Attempting to modify a string literal causes undefined
behavior. x itself can be modified to point to a different array of
characters.
如何abcde存储在内存中?我们可以在内存中找到x,但是我们不能用b $ b来操作它吗?
How does "abcde" stored in memory? we can find x in memory, but we can''t
operate it?
和
char y [] = {" abcde"};
and
char y[]={"abcde"};
y是一个包含6个字符的数组,用字符串文字初始化。
y中的字符可以更改。
y is an array of 6 characters, initialized with the string literal.
The characters in y can be changed.
我不能在函数中修改变量x的值,但是y可以是
do。
还有其他类似的问题需要注意吗?
I can''t modify the value of the variable x in functions, but y can be do.
Is there any other similar problem need to be notice?
不,字符串文字的情况是一种特殊情况,除了宽字符串文字之外没有其他人喜欢它。
No, the situation with string literals is a special case and there are
no others like it, except for wide string literals.
提前致谢!
Wade Yin
Thanks in advance!
Wade Yin
-
Jack Klein
主页: http://JK-Technology.Com
comp.lang.c http://www.eskimo.co m / ~scs / C-faq / top.html
comp.lang.c ++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu。 edu /~a ... FAQ-acllc.html
这篇关于接下来的两个声明有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!