250+ TOP MCQs on Unions and Answers

C Objective Questions on “Unions”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Unions” along with answers, explanations and/or solutions:

1. The size of a union is determined by the size of the __________
a) First member in the union
b) Last member in the union
c) Biggest member in the union
d) Sum of the sizes of all members
Answer: c
Clarification: None.

2. Which member of the union will be active after REF LINE in the following C code?

  1.     #include 
  2.     union temp
  3.     {
  4.         int a;
  5.         float b;
  6.         char c;
  7.     };
  8.     union temp s = {1,2.5,’A’}; //REF LINE

a) a
b) b
c) c
d) Such declaration are illegal
Answer: a
Clarification: None.

3. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1)

  1.     #include 
  2.     union uTemp
  3.     {
  4.         double a;
  5.         int b[10];
  6.         char c;
  7.     }u;

a) 4
b) 8
c) 40
d) 80
Answer: c
Clarification: None.

4. What type of data is holded by variable u int in the following C code?

  1.     #include 
  2.     union u_tag
  3.     {
  4.         int ival;
  5.         float fval;
  6.         char *sval;
  7.     } u;

a) Will be large enough to hold the largest of the three types;
b) Will be large enough to hold the smallest of the three types;
c) Will be large enough to hold the all of the three types;
d) None of the mentioned
Answer: a
Clarification: None.

5. Members of a union are accessed as________________
a) union-name.member
b) union-pointer->member
c) both union-name.member & union-pointer->member
d) none of the mentioned
Answer: c
Clarification: None.

6. In the following C code, we can access the 1st character of the string sval by using _______

  1.     #include 
  2.     struct
  3.     {
  4.         char *name;
  5.         union
  6.         {
  7.             char *sval;
  8.         } u;
  9.     } symtab[10];

a) *symtab[i].u.sval
b) symtab[i].u.sval[0].
c) You cannot have union inside structure
d) Both *symtab[i].u.sval & symtab[i].u.sval[0].
Answer: d
Clarification: None.

7. What will be the output of the following C code (Assuming size of int and float is 4)?

  1.     #include 
  2.     union
  3.     {
  4.         int ival;
  5.         float fval;
  6.     } u;
  7.     void main()
  8.     {
  9.         printf("%d", sizeof(u));
  10.     }

a) 16
b) 8
c) 4
d) 32
Answer: c
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     union stu
  3.     {
  4.         int ival;
  5.         float fval;
  6.     };
  7.     void main()
  8.     {
  9.         union stu r;
  10.         r.ival = 5;
  11.         printf("%d", r.ival);
  12.     }

a) 9
b) Compile time error
c) 16
d) 5
Answer: d
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *