MCQOPTIONS
Saved Bookmarks
This section includes 83 Mcqs, each offering curated multiple-choice questions to sharpen your Structures, Unions, Enums knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
What will be the output of the following C code? #include enum example {a = 1, b, c}; enum example example1 = 2; enum example answer() { return example1; } int main() { (answer() == a)? printf("yes"): printf("no"); return 0; } |
| A. | yes |
| B. | no |
| C. | 2 |
| D. | error |
| Answer» C. 2 | |
| 52. |
What will be the output of the following C code? main() { enum resut {pass, fail}; enum result s1,s2; s1=pass; s2=fail; printf("%d",s1); } |
| A. | error |
| B. | pass |
| C. | fail |
| Answer» B. pass | |
| 53. |
What will be the output of the following C code? #include enum class { a,b,c }; enum class m; main() { printf("%d",sizeof(m)); } |
| A. | 3 |
| B. | Same as the size of an integer |
| C. | 3 times the size of an integer |
| D. | Error |
| Answer» C. 3 times the size of an integer | |
| 54. |
Pick the incorrect statement with respect to enums. |
| A. | Two enum symbols cannot have the same value |
| B. | Only integer constants are allowed in enums |
| C. | It is not possible to change the value of enum symbols |
| D. | Enum variables are automatically assigned values if no value is specified |
| Answer» B. Only integer constants are allowed in enums | |
| 55. |
What is the output of this program? #include void main() { struct number { int no; char name[20]; }; struct number s; s.no = 50; printf("%d", s.no); } |
| A. | Nothing |
| B. | Compile time error |
| C. | Junk |
| D. | 50 |
| Answer» E. | |
| 56. |
For the following function call which option is not possible? func(&s.a); //where s is a variable of type struct and a is the member of the struct. |
| A. | Compiler can access entire structure from the function |
| B. | Individual members address can be displayed in structure |
| C. | Individual member can be passed by reference in a function |
| D. | None of the above |
| Answer» B. Individual members address can be displayed in structure | |
| 57. |
Which of the following is an incorrect syntax to pass by reference a member of a structure in a function? (Assume: struct temp{int a;}s;) |
| A. | func(&s.a); |
| B. | func(&(s).a); |
| C. | func(&(s.a)); |
| D. | None of the above |
| Answer» E. | |
| 58. |
Number of bytes in memory taken by the below structure is #include struct test { int k; char c; }; |
| A. | Multiple of integer size |
| B. | Integer size+character size |
| C. | Depends on the platform |
| D. | Multiple of word size |
| Answer» B. Integer size+character size | |
| 59. |
Which of the following are incorrect syntax for pointer to structure? (Assuming struct temp{int b;}*my_struct;) |
| A. | *my_struct.b = 10; |
| B. | (*my_struct).b = 10; |
| C. | my_struct->b = 10; |
| D. | Both *my_struct.b = 10; and (*my_struct).b = 10; |
| Answer» B. (*my_struct).b = 10; | |
| 60. |
What is the output of this program? #include struct student { char *c; }; void main() { struct student s[2]; printf("%d", sizeof(s)); } |
| A. | 2 |
| B. | 4 |
| C. | 16 |
| D. | 8 |
| Answer» E. | |
| 61. |
What is the output of this program? #include struct student { int no = 5; char name[20]; }; void main() { struct student s; s.no = 8; printf("hello"); } |
| A. | Nothing |
| B. | Compile time error |
| C. | hello |
| D. | Varies |
| Answer» C. hello | |
| 62. |
What is the output of this program? #include struct employee { char *empname; int salary; }; int main() { struct employee e, e1; e.empname = "Sridhar"; e1 = e; printf("%s %s", e.empname, e1.empname); return 0; } |
| A. | Garbage value Sridhar |
| B. | Sridhar Garbage value |
| C. | Sridhar Sridhar |
| D. | Compilation Error |
| Answer» D. Compilation Error | |
| 63. |
What is the output of this program? #include int main(){ struct leader { char *lead; int born; }; struct leader l1 = {"AbdulKalam", 1931}; struct leader l2 = l1; printf("%s %d", l2.lead, l1.born); } |
| A. | Compilation error |
| B. | Garbage value 1931 |
| C. | AbdulKalam 1931 |
| D. | None of the above |
| Answer» D. None of the above | |
| 64. |
What is the output of this program? #include int main(){ struct simp { int i = 6; char city[] = "chennai"; }; struct simp s1; printf("%d",s1.city); printf("%d", s1.i); return 0; } |
| A. | chennai 6 |
| B. | Nothing will be displayed |
| C. | Runtime Error |
| D. | Compilation Error |
| Answer» E. | |
| 65. |
What is the output of this program? #include struct { int i; float ft; }decl; int main(){ decl.i = 4; decl.ft = 7.96623; printf("%d %.2f", decl.i, decl.ft); return 0; } |
| A. | 4 7.97 |
| B. | 4 7.96623 |
| C. | Compilation error |
| D. | None of the above |
| Answer» B. 4 7.96623 | |
| 66. |
What is the output of this program? void main() { struct bitfields { int bits_1: 2; int bits_2: 9; int bits_3: 6; int bits_4: 1; }bit; printf("%d", sizeof(bit)); } |
| A. | 2 |
| B. | 3 |
| C. | 4 |
| Answer» C. 4 | |
| 67. |
What is the output of this program? #include int main() { enum days {MON=-1, TUE, WED=4, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d", MON, TUE, WED, THU, FRI, SAT); return 0; } |
| A. | -1 0 4 5 6 7 |
| B. | -1 0 1 2 3 4 |
| C. | 0 1 2 3 4 5 |
| D. | Error |
| Answer» B. -1 0 1 2 3 4 | |
| 68. |
What is the output of this program? #include void main() { struct demo{ char * a; int n; }; struct demo p = {"hello", 2015}; struct demo q = p; printf("%d", printf("%s",q.a)); } |
| A. | hello |
| B. | 5hello |
| C. | hello5 |
| D. | 6hello |
| Answer» D. 6hello | |
| 69. |
What is the output of this program? #include int main() { union demo { int x; int y; }; union demo a = 100; printf("%d %d",a.x,a.y); } |
| A. | 100 0 |
| B. | 100 100 |
| C. | 0 0 |
| D. | Compilation Error |
| Answer» E. | |
| 70. |
Which of the following accesses a variable in structure b? |
| A. | b->var; |
| B. | b.var; |
| C. | b-var; |
| D. | b>var; |
| Answer» C. b-var; | |
| 71. |
What will be the size of the following structure? struct demo{ int a; char b; float c; } |
| A. | 12 |
| B. | 8 |
| C. | 10 |
| D. | 9 |
| Answer» B. 8 | |
| 72. |
What is the output of this program? #include struct result{ char sub[20]; int marks; }; void main() { struct result res[] = { {"Maths",100}, {"Science",90}, {"English",85} }; printf("%s ", res[1].sub); printf("%d", (*(res+2)).marks); } |
| A. | Maths 100 |
| B. | Science 85 |
| C. | Science 90 |
| D. | Science 100 |
| Answer» C. Science 90 | |
| 73. |
What is the output of this program? #include struct test { int x; char y; } test; int main() { test.x = 10; test.y = 'A'; printf("%d %c", test.x,test.y); return 0; } |
| A. | 0.416666666666667 |
| B. | garbage value garbage value |
| C. | Compilation Error |
| D. | None of these |
| Answer» B. garbage value garbage value | |
| 74. |
What is the output of this program? #include struct test { int x = 0; char y = 'A'; }; int main() { struct test t; printf("%d, %c", s.x, s.y); return 0; } |
| A. | Error |
| B. | garbage value garbage value |
| C. | None of these |
| Answer» C. None of these | |
| 75. |
Which of the following is a properly defined struct? |
| A. | struct {int a;} |
| B. | struct a_struct {int a;} |
| C. | struct a_struct int a; |
| D. | struct a_struct {int a;}; |
| Answer» E. | |
| 76. |
Which of the following accesses a variable in structure *b? |
| A. | b->var; |
| B. | b.var; |
| C. | b-var; |
| D. | b>var; |
| Answer» B. b.var; | |
| 77. |
Which properly declares a variable of struct foo? |
| A. | struct foo; |
| B. | struct foo var; |
| C. | foo; |
| D. | int foo; |
| Answer» C. foo; | |
| 78. |
Which operator connects the structure name to its member name? |
| A. | - |
| B. | . |
| C. | Both (b) and (c) |
| D. | None of the above |
| Answer» C. Both (b) and (c) | |
| 79. |
Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed. union test { int x; char arr[4]; int y; }; int main() { union test t; t.x = 0; t.arr[1] = 'G'; printf("%s", t.arr); return 0; } |
| A. | Nothing is printed |
| B. | G |
| C. | Garbage character followed by 'G' |
| D. | Garbage character followed by 'G', followed by more garbage characters |
| Answer» B. G | |
| 80. |
#include struct st { int x; struct st next; }; int main() { struct st temp; temp.x = 10; temp.next = temp; printf("%d", temp.next.x); return 0; } |
| A. | Compiler Error |
| B. | 10 |
| C. | Runtime Error |
| D. | Garbage Value |
| Answer» B. 10 | |
| 81. |
Consider the following C declaration struct { short s[5]; union { float y; long z; }u; } t; Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is |
| A. | 22 bytes |
| B. | 14 bytes |
| C. | 18 bytes |
| D. | 10 bytes |
| Answer» D. 10 bytes | |
| 82. |
Consider the following C declaration struct ( short s[5]; union { float y; long z; }u; }t; Assume that the objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment consideration, is |
| A. | 22 bytes |
| B. | 18 bytes |
| C. | 14 bytes |
| D. | 10 bytes |
| Answer» C. 14 bytes | |
| 83. |
#include stdio.h int main() { struct site { char name[] = "GeeksQuiz"; int no_of_pages = 200; }; struct site *ptr; printf("%d ", ptr->no_of_pages); printf("%s", ptr->name); getchar(); return 0; } |
| A. | 200 GeeksQuiz |
| B. | 200 |
| C. | Runtime Error |
| D. | Compiler Error |
| Answer» E. | |