-
What will be the output of the following C code?
#include <stdio.h>
union Un
{
struct str
{
unsigned char ch : 2;
unsigned int n : 2;
};
int ch;
};
int main()
{
union Un u;
Un.str.ch = 2;
printf("%d\n", Un.str.ch);
}
-
- Compilation Error
- Garbage value
- 2
- Nothing
- None of these
Correct Option: A
Compilation Error
main.c:8:10: warning: declaration does not declare anything
};
^
main.c: In function ‘main’:
main.c:14:9: error: ‘Un’ undeclared (first use in this function)
Un.str.ch = 2;
^~
main.c:14:9: note: each undeclared identifier is reported only once for each function it appears in