C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - True / False Questions (Q.No. 3)
3.
Bit fields CANNOT be used in union.
True
False
Answer: Option
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

Discussion:
20 comments Page 2 of 2.

Sankari said:   9 years ago
Give any two difference between union and structure.

Sathuragiri said:   1 decade ago
What you mean by bit field? explain well?

Ranjana said:   1 decade ago
Why we made union. What is its purpose?

Preeti said:   1 decade ago
Yes. @Soumya Roy you are right.

Saltwind said:   7 years ago
What is meant by bitfields?

Kavin said:   1 decade ago
Please explain bit field?

Rijo said:   9 years ago
What is a bit field?

Sanjul said:   1 decade ago
What is bit field?

Sirisha said:   1 decade ago
What is bit field?

Ishwarya said:   7 years ago
What is bit field?


Post your comments here:

Your comments will be displayed after verification.