This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Unions – 2”.
Pre-requisite for C Unions MCQ set: Video Tutorial on C Unions.
1. What will be the output of the following C code?
#include <stdio.h>
union
{
int x;
char y;
}p;
int main()
{
p.x = 10;
printf("%d\n", sizeof(p));
}
a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(int)
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
union
{
int x;
char y;
}p;
int main()
{
p.y = 60;
printf("%d\n", sizeof(p));
}
a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(char)
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
union p
{
int x;
char y;
};
int main()
{
union p p, b;
p.y = 60;
b.x = 12;
printf("%d\n", p.y);
}
a) Compile time error
b) Depends on the compiler
c) 60
d) Undefined behaviour
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
union p
{
int x;
char y;
}k = {1, 97};
int main()
{
printf("%d\n", k.y);
}
a) Compile time error
b) 97
c) a
d) 1
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
union p
{
int x;
char y;
}k = {.y = 97};
int main()
{
printf("%d\n", k.y);
}
a) Compile time error
b) 97
c) a
d) Depends on the standard
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
union p
{
int x;
float y;
};
int main()
{
union p p, b;
p.x = 10;
printf("%f\n", p.y);
}
a) Compile time error
b) Implementation dependent
c) 10.000000
d) 0.000000
View Answer
Explanation: None.
7. Which of the following share a similarity in syntax?
1. Union, 2. Structure, 3. Arrays and 4. Pointers
a) 3 and 4
b) 1 and 2
c) 1 and 3
d) 1, 3 and 4
View Answer
Explanation: None.
8. What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8)
#include <stdio.h>
union utemp
{
int a;
double b;
char c;
}u;
int main()
{
u.c = 'A';
u.a = 1;
printf("%d", sizeof(u));
}
a) 1
b) 4
c) 8
d) 13
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
- Practice BCA MCQs
- Buy Computer Science Books
- Watch Advanced C Programming Videos
- Apply for C Internship
- Buy C Books