Machine-translated by Google. Questions are authored in English.
Top

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

 

  • A.Sanfoundry.name
  • B.nSanfoundry
  • C.Sanfoundry
  • D.Error

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.