Home » C Programming » Typedef » Question
  1. What will be the output of the following C code?
    #include <stdio.h>
    typedef struct NN
    {
    int n, m;
    }s = {11, 22};
    int main()
    {
    NN nn = s;
    printf("%d\n", nn.n);
    }
    1. Depends on the standard
    2. 11
    3. 22
    4. Garbage value
    5. Compilation Error
Correct Option: E

Compilation Error

main.c:5:5: error: typedef ‘s’ is initialized (use __typeof__ instead)
}s = {11, 22};
^
main.c: In function ‘main’:
main.c:8:9: error: unknown type name ‘NN’; use ‘struct’ keyword to refer to the type
NN nn = s;
^~
struct
main.c:8:17: error: expected expression before ‘s’
NN nn = s;
^
main.c:9:26: error: request for member ‘n’ in something not a structure or union
printf("%d\n", nn.n);



Your comments will be displayed only after manual approval.