Home » C Programming » Structures » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    struct
    {
    int n;
    char m;
    } stru;
    int stru = 110;
    int main()
    {
    stru.n = 110;
    printf("%d %d\n", stru.n, stru);
    }
    1. 110 110
    2. Compilation Error
    3. Garbage value
    4. Undefined behaviour
    5. None of these
Correct Option: B

Compilation Error

main.c:7:9: error: conflicting types for ‘stru’
int stru = 110;
^~~~
main.c:6:7: note: previous declaration of ‘stru’ was here
} stru;
^~~~
main.c: In function ‘main’:
main.c:10:13: error: request for member ‘n’ in something not a structure or union
stru.n = 110;
^
main.c:11:31: error: request for member ‘n’ in something not a structure or union
printf("%d %d\n", stru.n, stru);



Your comments will be displayed only after manual approval.