Log In Register

Units


Unions - Questions and Answers

 

Practice these Unions under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Unions for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Unions of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Unions.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Unions under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Unions topic of C Programming:

 

1.

What is the output of this C code?

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

the first character of the string sval by either of 

Answer: Option A

Explanation:

2.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union
  3.     {
  4.         int x;
  5.         char y;
  6.     }p;
  7.     int main()
  8.     {
  9.         p.y = 60;
  10.         printf("%d\n", sizeof(p));
  11.     }

Answer: Option B

Explanation:

3.

Which of the following share a similarity in syntax?
     1. Union, 2. Structure, 3. Arrays and 4. Pointers

Answer: Option D

Explanation:

4.

What would be the size of the following union declaration?

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

(Assuming size of double = 8, size of int = 4, size of char = 1) 

Answer: Option B

Explanation:

5.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union
  3.     {
  4.         int x;
  5.         char y;
  6.     }p;
  7.     int main()
  8.     {
  9.         p.x = 10;
  10.         printf("%d\n", sizeof(p));
  11.     }

Answer: Option A

Explanation:

6.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     }k = {.y = 97};
  7.     int main()
  8.     {
  9.         printf("%d\n", k.y);
  10.     }

Answer: Option C

Explanation:

7.

What is the output of this C code?

  1.     #include <stdio.h>
  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.     }

Answer: Option A

Explanation:

8.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.y = 60;
  11.         b.x = 12;
  12.         printf("%d\n", p.y);
  13.     }

Answer: Option B

Explanation:

9.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     }k = {1, 97};
  7.     int main()
  8.     {
  9.         printf("%d\n", k.y);
  10.     }

Answer: Option A

Explanation:

10.

What is the output of this C code(size of int and float is 4)?

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

Answer: Option B

Explanation:

11.

What type of data is holded by variable u int this C code?

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

The variable u here 

Answer: Option C

Explanation:

12.

Size of a union is determined by size of the.

Answer: Option B

Explanation:

13.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union utemp
  3.     {
  4.         int a;
  5.         double b;
  6.         char c;
  7.     }u;
  8.     int main()
  9.     {
  10.         u.c = 'A';
  11.         u.a = 1;
  12.         printf("%d", sizeof(u));
  13.     }

 The output will be: (Assuming size of char = 1, int = 4, double = 8) 

Answer: Option B

Explanation:

14.

Members of a union are accessed as________________

Answer: Option A

Explanation:

15.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union p
  3.     {
  4.         int x;
  5.         float y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.x = 10;
  11.         printf("%f\n", p.y);
  12.     }

Answer: Option C

Explanation: