#include #define N 30typedef struct char name
"error: assignment to expression via variety kind error"
s1.name="Paolo" s1.surname="Rossi" while if I do
information s1 = "Paolo", "Rossi", 19;it functions. What am I doing wrong?
c arrays string struct initialization
Improve this question
edited Jan 4 "19 at 6:48
128k1616 gold badges170170 silver badges239239 bronze badges
asked May 14 "16 at 10:02
57511 gold badge44 silver badges66 bronze badges
Add a comment |
3 Answers 3
Active Oldest Votes
You are facing concern in
s1.name="Paolo";bereason, in the LHS, you"re utilizing an array type, which is not assignable.
You are watching: Error: assignment to expression with array type
To intricate, from C11, chapter §6.5.16
assignment operator shall have a modifiable lworth as its left operand.
and also, regarding the modifiable lvalue, from chapter §22.214.171.124
A modifiable lvalue is an lworth that does not have actually range form, <...>
You should usage strcpy() to copy into the range.
See more: Helms Deep: Server Is Enforcing Consistency For This File Consistency
That sassist, information s1 = "Paolo", "Rossi", 19; works fine, bereason this is not a direct assignment entailing assignment operator. Tright here we"re using a brace-enclosed initializer list to provide the initial worths of the object. That adheres to the legislation of initialization, as pointed out in chapter §6.7.9
Each brace-enclosed initializer list has actually an linked current object. When no desigcountries are current, subobjects of the current object are initialized in order according to the kind of the present object: array aspects in raising subscript order, structure members in declaration order, and the first named member of a union.<....>