Exercise: Structures Unions Enums

Questions for: Structures Unions Enums

Bit fields CANNOT be used in union.
A:
True
B:
False
C:
D:
Answer: B

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

Nested unions are allowed
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
A union cannot be nested in a structure
A:
True
B:
False
C:
D:
Answer: B
No answer description is available. Let's discuss.
Which of the following statements correct about the below code?
maruti.engine.bolts=25;
A:
Structure bolts is nested within structure engine.
B:
Structure engine is nested within structure maruti.
C:
Structure maruti is nested within structure engine.
D:
Structure maruti is nested within structure bolts.
Answer: B
No answer description is available. Let's discuss.
Which of the following statements correctly assigns 12 to month using pointer variable pdt?
#include<stdio.h>

    struct date
    {
        int day;
        int month;
        int year;
    };
int main()
{
    struct date d;
    struct date *pdt;
    pdt = &d;
    return 0;
}
A:
pdt.month = 12
B:
&pdt.month = 12
C:
d.month = 12
D:
pdt->month = 12
Answer: D
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz