本文介绍了指定字符串之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C我试图在两种不同的方式分配刺痛变量
In C I tried to assign a sting to variable in two different ways
char question[200]; strcpy( question, "This is the question" );和
char question[] = "This is the question";和这两个作品...但什么是这两种方法之间的区别?
and both works... but what's the difference between these two methods?
推荐答案,这种差异可能的灵活性。这
The difference is probably flexibility. This
strcpy( question, "This is the question" );在声明变量之后,你可以做任何时候。而这样的:
you can do anytime after you declare the variable. Whereas this:
char question[] = "This is the question";您必须在申报时直接使用。
You have to use directly during declaration time.
在第二例如问题的长度得到固定长度对于空终止文本+1。你不能改变这个变量的长度后,所以你不能分配较大字符串,它的例子。
In the second example the length of question got fixed to length of text +1 for null terminator. You can't change length of this variable later, so you can't assign larger string to it for example.
更多推荐
指定字符串之间的区别
发布评论