This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Unions – 1”.
Pre-requisite for C Unions MCQ set: Video Tutorial on C Unions.
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
View Answer
Explanation: None.
2. Which member of the union will be active after REF LINE in the following C code?
#include <stdio.h>
union temp
{
int a;
float b;
char c;
};
union temp s = {1,2.5,’A’}; //REF LINE
a) a
b) b
c) c
d) Such declaration are illegal
View Answer
Explanation: 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)
#include <stdio.h>
union uTemp
{
double a;
int b[10];
char c;
}u;
a) 4
b) 8
c) 40
d) 80
View Answer
Explanation: None.
4. What type of data is holded by variable u int in the following C code?
#include <stdio.h>
union u_tag
{
int ival;
float fval;
char *sval;
} 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
View Answer
Explanation: 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
View Answer
Explanation: None.
6. In the following C code, we can access the 1st character of the string sval by using _______
#include <stdio.h>
struct
{
char *name;
union
{
char *sval;
} u;
} 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].
View Answer
Explanation: None.
7. What will be the output of the following C code (Assuming size of int and float is 4)?
#include <stdio.h>
union
{
int ival;
float fval;
} u;
void main()
{
printf("%d", sizeof(u));
}
a) 16
b) 8
c) 4
d) 32
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
union stu
{
int ival;
float fval;
};
void main()
{
union stu r;
r.ival = 5;
printf("%d", r.ival);
}
a) 9
b) Compile time error
c) 16
d) 5
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C Internship
- Watch Advanced C Programming Videos
- Apply for Computer Science Internship
- Buy C Books
- Buy Computer Science Books