Home » C Programming » Bit Fields » Question
  1. 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);
    }
    1. Compilation Error
    2. Garbage value
    3. 2
    4. Nothing
    5. 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



Your comments will be displayed only after manual approval.