I’m new to C and experimenting with structs. After I’ve created a struct, is it possible to reassign it with curly brackets?
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;
}
Not directly, but C99 has compound literals for that
you could even do things more readable by using designated initializers like