Home » C Programming » Structures » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct Employee
    {
    char *Name;
    };
    struct Employee fun(void)
    {
    struct Employee emp1;
    emp1.Name = "Prayag";
    return emp1;
    }
    void main()
    {
    struct Employee emp2 = fun();
    emp1.Name = "Ajit";
    printf("%s", emp2.Name);
    }
    1. Prayag
    2. Ajit
    3. Compilation Error
    4. Garbage value
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘main’:
main.c:15:9: error: ‘emp1’ undeclared (first use in this function); did you mean ‘emp2’?
emp1.Name = "Ajit";
^~~~
emp2
main.c:15:9: note: each undeclared identifier is reported only once for each function it appears in



Your comments will be displayed only after manual approval.