【发布时间】:2025-12-30 13:00:15
【问题描述】:
对struct变量赋值有疑问。
struct udata
{
char name[50];
int num;
char ch;
};
void main()
{
struct udata a = {"ram", 20, 'a'};
struct udata b;
//b = {"ashok", 10, 'c'}; - illegal
b = a;
}
在上面的代码中b = {"ashok", 10, 'c'}; 给出了编译错误,但它接受了b = a;。我希望两者都是类似的任务,但我不知道为什么它不接受第一个任务。有人可以解释一下为什么会这样吗?
注意:我正在使用 fedora gcc 编译器进行编译。
【问题讨论】:
标签: c struct variable-assignment