-
What will be the output of the following C code?
#include <stdio.h>
union N
{
struct
{
unsigned char c : 2;
unsigned int num : 2;
}M;
int c;
};
int main()
{
union N n.M = {2};
printf("%d\n", n.M.c);
}
-
- Garbage value
- Nothing
- Compilation Error
- 2
- None of these
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:13:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
union N n.M = {2};
^
main.c:13:18: error: expected expression before ‘.’ token
main.c:14:24: error: ‘n’ undeclared (first use in this function)
printf("%d\n", n.M.c);
^
main.c:14:24: note: each undeclared identifier is reported only once for each function it appears in