我是 C 新手,正在尝试结构。创建结构后,是否可以用大括号重新分配它?
typedef struct {
int height;
int age;
} Person;
int main (void)
{
Person bill = {100,35};
bill = {120,34}; // error: expected expression before ‘{’ token
bill = Person {120,34}; // error: expected expression before ‘Person’
return 0;
}
不是直接的,但 C99 有复合文字
bill = (Person){120,34};
你甚至可以通过使用指定的初始化器来做一些更具可读性的事情,比如
bill = (Person){ .height = 120, .age = 34, };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)