C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 11)
11.
Point out the error in the program?
#include<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;
}
Answer: Option
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");
Discussion:
14 comments Page 2 of 2.
Sowmya said:
1 decade ago
can someone explain tis concept ?
Sam910 said:
1 decade ago
@afiz - why is it B?
There is no problem in the structure assignment
There is no problem in the structure assignment
Afiz said:
1 decade ago
Lvalue : left value, but this answer is wrong B is corrct
Preethi said:
1 decade ago
What is this Lvalue error? I have seen it many time.
What does it mean actually?.
Can anyone explain me please ?
What does it mean actually?.
Can anyone explain me please ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers