MCQOPTIONS
Saved Bookmarks
This section includes 24 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Which of the following is the correct output for the program given below?#include<studio.h>int main(){ union a { short int i; char ch[1]; }; union a u; u.ch[0] = 10; u.ch[1] = 20; printf("%d %d %d n", u.ch[0], u.ch[1], u.i); return 0;} |
| A. | 10 20 5130 |
| B. | 5130 10 20 |
| C. | 10 20 50 |
| D. | None of the above |
| Answer» B. 5130 10 20 | |
| 2. |
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 *Str; } u; } tab[15]; |
| A. | tab[i].u.Str[0]. |
| B. | *symtab[i].u.Str |
| C. | Both tab[i].u.Str[0]. & *tab[i].u.Str |
| D. | You cannot have union inside structure |
| E. | None of these |
| Answer» D. You cannot have union inside structure | |
| 3. |
What type of data is holded by variable u int in the following C code?#include <stdio.h> union Example { int Nval; float Fval; char *Sval; } e; |
| A. | Will be large enough to hold the smallest of the three types; |
| B. | Will be large enough to hold the all of the three types; |
| C. | Will be large enough to hold the largest of the three types; |
| D. | All of above |
| E. | None of these |
| Answer» D. All of above | |
| 4. |
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 Test { double n1; int n2[10]; char n; }t; |
| A. | 80 |
| B. | 8 |
| C. | 4 |
| D. | 40 |
| E. | None of these |
| Answer» E. None of these | |
| 5. |
Which member of the union will be active after REF LINE in the following C code?#include <stdio.h> union test { int n; float fl; char ch; }; union test t = {11,12.25, N }; //REF LINE |
| A. | n |
| B. | fl |
| C. | ch |
| D. | Such declaration are illegal |
| E. | None of these |
| Answer» B. fl | |
| 6. |
What will be the output of the following C code?#include <stdio.h> union U { int m; char s; }; int main() { union U u, uu; u.m = 65; uu.s = 32; printf("%d n", u.s); } |
| A. | Compilation Error |
| B. | Garbage value |
| C. | 65 |
| D. | 32 |
| E. | None of these |
| Answer» D. 32 | |
| 7. |
What will be the output of the following C code?#include <stdio.h> union { int n; char ch; }U; int main() { U.ch = 201; printf("%d n", sizeof(U)); } |
| A. | sizeof(int) + sizeof(char) |
| B. | sizeof(char) |
| C. | Compilation Error |
| D. | Depends on the compiler |
| E. | None of these |
| Answer» C. Compilation Error | |
| 8. |
What will be the output of the following C code?#include <stdio.h> union { int n; char ch; }U; int main() { U.n = 10; printf("%d n", sizeof(U)); } |
| A. | sizeof(int) |
| B. | Depends on the compiler |
| C. | sizeof(int) + sizeof(char) |
| D. | Compilation Error |
| E. | None of these |
| Answer» B. Depends on the compiler | |
| 9. |
What will be the output of the following C code (Assuming size of int and float is 4)?#include <stdio.h> union { int Nval; float Fval; } U; void main() { printf("%d", sizeof(U)); } |
| A. | 32 |
| B. | 16 |
| C. | 8 |
| D. | 4 |
| E. | None of these |
| Answer» E. None of these | |
| 10. |
What will be the output of the following C code?#include <stdio.h> union Employee { int N; float F; }; void main() { union Employee emp; emp.N = 26; printf("%d", emp.N); } |
| A. | Garbage value |
| B. | Compilation Error |
| C. | 26 |
| D. | Undefined behaviour |
| E. | None of these |
| Answer» D. Undefined behaviour | |
| 11. |
What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8)#include <stdio.h> union Example { int n1; double n2; char ch; }E; int main() { E.ch = 'B'; E.n1 = 100; printf("%d", sizeof(E)); } |
| A. | 32 |
| B. | 16 |
| C. | 8 |
| D. | 4 |
| E. | 2 |
| Answer» D. 4 | |
| 12. |
Which of the following share a similarity in syntax?1. Union2. Structure3. Arrays 4. Pointers |
| A. | 1 and 2 |
| B. | 3 and 4 |
| C. | 1, 3 and 4 |
| D. | 1 and 3 |
| E. | None of these |
| Answer» B. 3 and 4 | |
| 13. |
What will be the output of the following C code?#include <stdio.h> union U { int N; float F; }; int main() { union U u, uu; u.N = 200; printf("%f n", u.F); } |
| A. | Implementation dependent |
| B. | Compilation Error |
| C. | 200.000000 |
| D. | 0.000000 |
| E. | None of these |
| Answer» E. None of these | |
| 14. |
What will be the output of the following C code?#include <stdio.h> union U { int m; char Str; }s = {.Str = 99}; int main() { printf("%d n", s.Str); } |
| A. | Compilation Error |
| B. | Depends on compiler |
| C. | Garbage value |
| D. | 99 |
| E. | None of these |
| Answer» E. None of these | |
| 15. |
What will be the output of the following C code?#include <stdio.h> union S { int n; char ch; }u = {100, 99}; int main() { printf("%d n", u.ch); } |
| A. | 99 |
| B. | 100 |
| C. | Compilation Error |
| D. | Garbage value |
| E. | None of these |
| Answer» C. Compilation Error | |
| 16. |
The size of a union is determined by the size of the __________. |
| A. | Biggest member in the union |
| B. | Sum of the sizes of all members |
| C. | First member in the union |
| D. | Last member in the union |
| E. | None of these |
| Answer» B. Sum of the sizes of all members | |
| 17. |
In the following C code, we can access the 1st character of the string sval by using _______. |
| A. | tab[i].u.Str[0]. |
| B. | *symtab[i].u.Str |
| C. | Both tab[i].u.Str[0]. & *tab[i].u.Str |
| D. | You cannot have union inside structure |
| E. | None of these |
| Answer» D. You cannot have union inside structure | |
| 18. |
What will be the output of the following C code (Assuming size of int and float is 4)? |
| A. | 32 |
| B. | 16 |
| C. | 8 |
| D. | 4 |
| E. | None of these |
| Answer» E. None of these | |
| 19. |
What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1) |
| A. | 80 |
| B. | 8 |
| C. | 4 |
| D. | 40 |
| E. | None of these |
| Answer» E. None of these | |
| 20. |
Which member of the union will be active after REF LINE in the following C code? |
| A. | n |
| B. | fl |
| C. | ch |
| D. | Such declaration are illegal |
| E. | None of these |
| Answer» B. fl | |
| 21. |
What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8) |
| A. | 32 |
| B. | 16 |
| C. | 8 |
| D. | 4 |
| E. | 2 |
| Answer» D. 4 | |
| 22. |
Members of a union are accessed as________________. |
| A. | union-pointer->member |
| B. | union-name.member |
| C. | both union-pointer->member & union-name.member |
| D. | union-name.pointer |
| E. | None of these |
| Answer» D. union-name.pointer | |
| 23. |
What type of data is holded by variable u int in the following C code? |
| A. | Will be large enough to hold the smallest of the three types; |
| B. | Will be large enough to hold the all of the three types; |
| C. | Will be large enough to hold the largest of the three types; |
| D. | All of above |
| E. | None of these |
| Answer» D. All of above | |
| 24. |
Which of the following share a similarity in syntax? |
| A. | 1 and 2 |
| B. | 3 and 4 |
| C. | 1, 3 and 4 |
| D. | 1 and 3 |
| E. | None of these |
| Answer» B. 3 and 4 | |