指定字符数组在C值 [英] Assigning char array a value in C

查看:144
本文介绍了指定字符数组在C值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么区别:

char fast_car[15]="Bugatti";

char fast_car[15];
fast_car="Bugatti";

由于第二个结果与编译错误:

Because the second one results with compile error:

错误:分配给从类型类型的char [15]'时不兼容的类型
  字符*

error: incompatible types when assigning to type ‘char[15]’ from type ‘char *’

在第一个工作正常。在不同的地方放一个字符串数组比阵列的初始化将是有益的。

While the first one works fine. Putting a string in array in different place than array initialisation would be helpful.

推荐答案

第一个是一个的初始化的而第二个是一个的分配的。因为数组是不是在C修改值不能分配新的值给他们。

The first is an initialization while the second is an assignment. Since arrays aren't modifiable values in C you can't assign new values to them.

你要知道,你的可以修改数组内容,你就不能说 fast_car = ... 。因此,内容修改,阵列本身并不

Mind you, you can modify array contents, you just can't say fast_car = .... So the contents are modifiable, the arrays themselves are not.

使用相同的符号 = 这些广泛不同的概念是值得商榷的价值。

Using the same symbol = for these widely different concepts is of debatable value.

这篇关于指定字符数组在C值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆