Discussion
What will be the output of the following C code? (If the name entered is: Sanfoundry)
#include <stdio.h>
#include <string.h>
typedef struct employee
{
char name[50];
int salary;
} e1;
void main( )
{
printf("Enter Employee name");
scanf("%s",e1.name);
printf("\n%s",e1.name);
}
Answer: D
Correct answer: Error
The declaration ends } e1;, and because it begins with typedef, e1 is the name of a type, not a variable. Writing e1.name therefore applies the member operator to a type name, which the compiler rejects. Without the typedef keyword the same line would have declared e1 as a variable and the program would have worked.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development