Home » C Programming » Structures » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct student
    {
    char *name;
    };
    void main()
    {
    struct student s1[2], s2[2];
    s1[1] = s1[0] = "Ajit Kumar Gupta";
    printf("%s %s", s1[0].name, s1[1].name);
    }
    1. Compilation Error
    2. Garbage value
    3. Ajit Kumar Gupta
    4. Undefined behaviour
    5. None of these
Correct Option: A

Compilation Error

main.c: In function ‘main’:
main.c:9:23: error: incompatible types when assigning to type ‘struct student’ from type ‘char *’
s1[1] = s1[0] = "Ajit Kumar Gupta";



Your comments will be displayed only after manual approval.