Sail E0 Webinar
Question


Point out the error in the program?


#includ<stdio.h>
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;
}
Options:
A .  Error: Lvalue required/incompatible types in assignment
B .  Error: invalid constant expression
C .  Error: Rvalue required
D .  No error, Output: Suresh 25
Answer: Option A

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");



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers