指定字符串之间的区别

编程入门 行业动态 更新时间:2024-10-24 21:27:55
本文介绍了指定字符串之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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.

更多推荐

指定字符串之间的区别

本文发布于:2023-10-19 14:54:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   区别

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!