-
What will be the output of the following C code?
#include <stdio.h>
typedef struct B
{
int n1, n2;
};
int main()
{
B k = {10, 20};
printf("%d\n", k.n1);
}
-
- 10
- 20
- Compilation Error
- Undefined behaviour
- None of these
Correct Option: C
Compilation Error
main.c:5:5: warning: useless storage class specifier in empty declaration
};
^
main.c: In function ‘main’:
main.c:8:9: error: unknown type name ‘B’; use ‘struct’ keyword to refer to the type
B k = {10, 20};
^
struct
main.c:8:20: warning: excess elements in scalar initializer
B k = {10, 20};
^~
main.c:8:20: note: (near initialization for ‘k’)
main.c:9:25: error: request for member ‘n1’ in something not a structure or union
printf("%d\n", k.n1);