union Point { unsigned int x:4; unsigned int y"> union Point { unsigned int x:4; unsigned int y">
logo

CuriousTab

CuriousTab

Discussion


Home C Programming Structures, Unions, Enums Comments

  • Question
  • Bit fields CANNOT be used in union.


  • Options
  • A. True
  • B. False

  • Correct Answer
  • False 

    Explanation
    The following is the example program to explain "using bit fields inside an union".

    #include<stdio.h>
    
    union Point
    {
      unsigned int x:4;
      unsigned int y:4;
      int res;
    };
    
    int main()
    {
       union  Point pt;
    
       pt.x = 2;
       pt.y = 3;
       pt.res = pt.y;
    
       printf("\n The value of res = %d" , pt.res);
    
       return 0;
    }
    // Output: The value of res = 3
    


    Structures, Unions, Enums problems


    Search Results


    • 1. A union cannot be nested in a structure

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. The '.' operator can be used access structure elements using a structure variable.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. Which of the following statement is True?

    • Options
    • A. User has to explicitly define the numeric value of enumerations
    • B. User has a control over the size of enumeration variables.
    • C. Enumeration can have an effect local to the block, if desired
    • D. Enumerations have a global effect throughout the file.
    • Discuss
    • 4. The '->' operator can be used to access structures elements using a pointer to a structure variable only

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. Union elements can be of different sizes.

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. one of elements of a structure can be a pointer to the same structure.

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. A structure can contain similar or dissimilar elements

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. It is not possible to create an array of pointer to structures.

    • Options
    • A. True
    • B. False
    • Discuss
    • 9. If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?
      struct ex
      {
          char ch;
          int i;
          long int a;
      };
      

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 10. Can we have an array of bit fields?

    • Options
    • A. Yes
    • B. No
    • Discuss


    Comments

    There are no comments.

Enter a new Comment