Home » C Programming » Structures, Unions, Enums

Point out the error in the program? #include int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; e.age = 25; printf("%s %d\n", e.name, e.age); return 0; }

Correct Answer: Error: Lvalue required/incompatible types in assignment

Explanation:

We cannot assign a string to a struct variable like e.name = "Suresh"; in C.


We have to use strcpy(char *dest, const char *source) function to assign a string.
Ex: strcpy(e.name, "Suresh");


← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion