关于C++结构体、数组还有指针的问题
1.char test[20]="xxxxx";编译是不会出错的。
2.struct student
{
int num;
char name[20];
float score[3];
};
void main(int argc, char* argv[])
{
struct student stu;
stu.name="xxxxx";
}
会报:
error C2440: '=' : cannot convert from 'char [6]' to 'char [20]'
There is no context in which this conversion is possible
这样的错误。
3.改成struct student
{
int num;
char name[6];
float score[3];
};
void main(int argc, char* argv[])
{
struct student stu;
stu.name="xxxxx";
}
则会报:
error C2106: '=' : left operand must be l-value
4.将char name[20];改为char *name;就不会报错了。
请问上面为什么报错?
jinpengxx8
2012/03/02 15:30- 数组
- 结构体
- 指针
- 点赞
- 收藏
- 回答
满意答案