-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_comp_questions.sql
2199 lines (1522 loc) · 66.5 KB
/
main_comp_questions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (1, '#include<iostream>
using namespace std;
int main()
{
void add(int x,int y);
int add(int p,int q);
return 0;
}', 'Run time error', 'Compile time error', 'Runs successfully', 'None', 'Compile time error', 'Note: in function int main()
Error: ambiguating new declaration of ''int add(int, int)''');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (2, 'Which is not the false statement for new operator?', 'It cant be overloaded', 'It returns garbage value when memory allocation fails', 'It automatically computes the size of data object', 'All of the above', 'It automatically computes the size of data object', 'new operator can be overloaded and it returns NULL when memory allocation fails');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (4, '//What is output?
#include<iostream>
using namespace std;
struct stud
{
int roll;
};
class result:public stud
{
public:
void getdata()
{
cout<<"Enter roll no";
cin>>roll;
}
void show()
{
cout<<"Roll no. is"<<roll;
}
};
int main()
{
result r;
r.getdata();
r.show();
return 0;
}
//Consider the input roll no as 22', 'Enter roll no', 'Compile time error as structure cannot be inherited', 'Enter roll no 22 Roll no is 22', 'none', 'Enter roll no 22 Roll no is 22', 'Structure can be inherited');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (7, 'Generic pointers can be declared with______', 'auto', 'asm', 'void', 'none', 'void', 'void keyword is used to declare generic pointers');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (8, 'Which of the following is true for static variables of a class?
i. We can initialize a value of static variable only when its
object is created
ii. Static variables must be declared in public section of
class
iii. Static variables in a class is initialized when 1st object
is created', 'i,iii', 'ii,iii', 'i,ii', 'None', 'ii,iii', 'Static variables can also be initialized before its object is created');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (9, 'Output for the following code is:
#include<iostream>
using namespace std;
class birds
{
};
class peacock:protected birds
{
};
int main()
{
return 0;
}', 'It will not compile because class body of birds is not defined', 'It will not compile because class body of peacock is not defined', 'It will not compile because empty class cannot be protectedly inherited from other class', 'It will compile successfully.', 'It will compile successfully.', 'It is not necessary to define data members & functions inside class');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (10, '_____ allows that a section of a program is compiled only if the defined
constant that is specified as the parameter has been defined independently
of its value', '#define', '#ifd', '#ifdef', 'none', '#ifdef', '#ifdef is the header file which allows to specify constants as a parameter and define it independently of its value.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (11, 'question 1//What is output?
#include<iostream>
using namespace std;
void fun(int x,int y)
{
x=20;
y=10;
}
int main()
{
int x=10;
fun(x,x);
cout<<x;
return 0;
}', 10, 20, 'compile time error', 'none', 10, 'Value of x is passed by value.
It remains same after exiting the function scope');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (12, 'How many ways are there to pass values to a function?', 1, 3, 0, 2, 3, 'Pass by value, reference, pointers');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (13, '#include<iostream>
using namespace std;
class book
{
static int x;
public:
book()
{
x++;
}
static int getx()
{
return x;
}
};
int book::x=0;
int main()
{
cout<<book::getx()<<" ";
book b[5];
cout<<book::getx();
return 0;
}', '0 0', '5 5', '0 5', 'None', '0 5', 'x is firstly initialized to 0 automatically so x=0
then 5 objects are created ,so x is incremented 5 times and x=5');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (14, 'A class is defined as follows:
#include <iostream>
using namespace std;
class abc
{
private: int a;
public: friend void getdata(void);
};
void getdata(void);
int main()
{
return 0;
}
The correct header for defining getdata() function outside the class is ____', 'friend void abc::getdata(void);', 'void abc::getdata(void);', 'friend void getdata(void);', 'void getdata(void);', 'void getdata(void);', 'Friend function is defined in syntax as:
return_type name(data_type);');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (15, 'Which of the following manipulator is used for representing octal equivalent
of a given decimal number?', 'oct', 'set base(8)', 'tobase(8)', 'both a and b', 'both a and b', 'oct and set base(8) both are used for representing octal equivalent of a binary no.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (16, 'In case of inheritance where both base and derived class are having constructor
and destructor then which is true?
i. Constructors are executed in their order of derivation
ii. Constructors are executed in reverse order of derivation
iii. Destructors are executed in the order of derivation
iv. Destructors are executed in reverse order of derivation', 'only 2,4', 'only 1,3', 'only 1,4', 'only 2,3', 'only 1,4', 'Constructors are executed in their order of derivation and Destructors are executed in reverse order of derivation');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (17, 'In multiple inheritance, in order to remove duplicate set of records in child class, we___', 'Write virtual function in parent classes', 'Write virtual function in base class', 'make base class as virtual base class', 'all', 'make base class as virtual base class', 'Ambiguity is resolved by making base class as virtual base class in multiple inheritance');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (18, 'Inline functions may not work if____
i. If function contains static variables
ii. If function contains global and register variables
iii. If function returning value consists looping constants
iv. If inline function are recursive
v. If function contains constant value', 'only 1,4,5', 'only 2,3,5', 'only 1,3,4', 'All of the above', 'only 1,3,4', 'Inline functions does not contain static variables, loops,recursive functions');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (19, 'Which is a valid statement?', 'void calc(int amt,int yr,float rate=7.8);', 'void calc(int amt=21,int yr,float rate=7.8);', 'void calc(int amt=20,int yr=5,float rate);', 'All of the above', 'void calc(int amt,int yr,float rate=7.8);', 'Syntax for default parameters for 3 parameters:
return_type name(type var1,type var2,type var3=value );');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (20, 'Function overloading can be achieved if:', '2 or more functions differ only in return types', 'If they have different number of arguments', 'If 2 or more functions differ only in types of arguments', 'All of the above', 'If they have different number of arguments', 'For Function overloading , it is necessary to have different number of arguments or different return types
or different types of arguments
It gives compile time error if function differs only in return type or in types of arguments');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (21, 'By default, files are opened in _____ mode', 'binary', 'text', 'write only', 'none', 'text', 'Default mode is text for file handling');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (22, 'Which of the following statements are true?', 'Non-member function cannot have access to the private data of the class', 'A function can be declared as friend maximum only in 2 classes', 'A friend function has this pointer associated with it', 'All', 'A friend function has this pointer associated with it', 'Non member can access if it is a friend of that class and any no. of functions can be declared as friend');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (23, 'Which is not false about friend function
i. It can be invoked with class object
ii. It has objects as arguments
iii. It can have built-in types as arguments
iv. It must be declared in public
v. It does not have this pointer as argument', 'only 2,4', 'only 1,2,5', 'only 2,3,5', 'All of the above', 'only 2,3,5', 'Friend function cannot be invoked with object and has to be declared in private section');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (24, 'Which of the following are true for virtual functions?', 'They must be non static-member function of the class', 'They cannot be friends', 'Constructor functions cannot be virtual', 'All of these', 'All of these', 'virtual function cant be static member functions
They cant be friends, and only member functions can be virtual');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (25, 'Which is the false statement for abstract class', 'Objects cannot be created', 'Pointers cannot be created to an abstract class', 'It contains at least 1 pure virtual function', 'References can be created to an abstract class', 'Pointers cannot be created to an abstract class', 'Pointers can be created to any class and objects cannot be created of abstract class');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (26, 'Which of the following is correct for an assignment statement', 'The lvalue must always be a variable', 'The rvalue mght be constant,a variable, an expression or any combination of these', 'The assignment always takes place from right to left', 'All of the above', 'All of the above', 'Assignment operator rules');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (27, 'Find output -
#include<stdio.h>
int main()
{
printf("%d",sizeof(7.2));
return 0;
}', 4, 8, 16, 2, 8, 'size alloted to floating point decimal number is 8 by compiler');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (28, 'int main() {
union Data {
int i_;
float f_;
unsigned char str[20];
} data;
printf("size = %d\n", sizeof(data));
data.i_ = 10;
data.f_ = 220.5;
printf( "data.i_ : %d\n", data.i_);
return 0;
}', 28, 32, 20, 24, 20, 'Maximum size is 20');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (29, 'What will be the output of the following program?
#include <iostream>
#include <algorithm>
using namespace std;
bool compare (int i, int j) { return (i > j); }
int main()
{
int data[] = {1, 2, 3, 4, 5};
rotate (data, data+4, data+5);
for(int i = 0; i < 5; ++i)
cout << data[i] <<" ";
return 0;
}', '3 4 5 1 2', '4 5 1 2 3', '5 1 2 3 4', '2 3 4 5 1', '5 1 2 3 4', 'explaination');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (30, 'Which function will change the state of the object?
#include<iostream>
using namespace std;
class Test
{
int x_;
int y_;
public:
void display()
{
cout << x << " " << y;
}
void set(int m_, int n_)
{
x_ = m_, y_ = n_;
}
};', 'Only set()', 'Only display()', 'display() and set() both', 'None of the above', 'Only set()', 'Explanation');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (31, 'What will be the output of the following program?
#include <iostream>
using namespace std;
class Sample {
public:
int data_, graph_;
Sample(int x = 0): data_(x), graph_(0) {
cout << data_ << " " << graph_ << " ";
}
Sample(int x, int y): data_(x), graph_(y) {
cout << data_ << " " << graph_ << " ";
}
};
int main() {
Sample s1(4), s2(3,4), s3;
return 0;
}', '4 0 3 4', '4 0 3 4 0 0', 'Compilation error', 'None of the above', '4 0 3 4 0 0', 'Explanation');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (32, 'What is the output?
#include <iostream>
using namespace std;
class Complex {
public: double *re, *im;
Complex(double r, double m) {
re = new double(r);
im = new double(m);
}
~Complex(){
delete re, im; cout << "destroy";
}
};
int main() {
Complex n1(4,5);
cout << *n1.re << "+" << *n1.im << "i ";
Complex n2 = n1;
cout << *n2.re << "+" << *n2.im << "i ";
*n1.im = 6;
cout << *n2.re << "+" << *n2.im << "i ";
cout << *n1.re << "+" << *n1.im << "i ";
return 0;
}', '4+5i 4+6i 4+5i 4+6i', '4+5i 4+5i 4+6i 4+6i', '4+5i 4+6i 4+6i 4+6i', '4+5i 4+5i 4+5i 4+6i', '4+5i 4+5i 4+6i 4+6i', 'Explanation');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (33, 'Why is it necessary to overload some operators in a class by a global function
(rather than a member function)?', 'Because member functions are slower than global functions', 'Because built-in types cannot have member functions', 'Because the left hand operand may not be an object of the class', 'Because the right hand operand may not be an object of the class', 'Because the left hand operand may not be an object of the class', 'Ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (34, '#include <iostream>
#include <string>
using namespace std;
class Animal {
int Age;
float Weight;
public:
void move() { }
void eat() { }
};
class Bird: public Animal {
public:
void fly(int m, int f) { }
};
void food(const Animal& a)
{
a.move();
}
void wings(const Bird& b) { b.fly(); }
int main() {
Animal an;
Bird bi;
return 0;
}
Which of the following is/are invalid function call/s?', 'food(an);', 'food(bi);', 'wings(bi);', 'wings(an);', 'wings(an);', 'Ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (35, 'Identify the lines on which the compiler will report an error.
#include <iostream> // ---1
using namespace std; // ---2
class Base { // ---3
int var_; // ---4
public: // ---5
Base():var_(0){} // ---6
}; // ---7
class Derived: public Base { public: // ---8
int varD_; // ---9
void print () { cout << var_; } // ---10
}; // ---11
int main() { // ---12
Derived d; // ---13
d.var_ = 1; // ---14
d.varD_ = 1; // ---15
cout << d.var_ <<" " << d.varD_; // ---16
return 0; // ---17
} // ---18', '6, 10, 14, 15', '6, 15', '6, 14, 16', '10, 14, 16', '10, 14, 16', 'Ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (36, 'What will be the output of the following program ?
#include <iostream>
using namespace std;
class B{ public: int base;
B() {}
~B() {}
};
class D: public B { public: int derived;
D() {}
~D() {}
};
int main() {
D d1;
B b1;
cout << &b1.base << " ";
cout << &d1.base;
return 0;
}', '0x28fef8 0x28fef8', '0x28fef8 0x28fefc', 'Compilation error', 'None of the above', '0x28fef8 0x28fefc', 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (37, 'What will be the output of the program
#include <iostream>
using namespace std;
class F1 {
public:
F1() { cout << "F1 ctor "; }
~F1() { cout << "F1 dtor "; }
};
class F2 : public F1 {
public:
F2() { cout << "F2 ctor "; }
~F2() { cout << "F2 dtor "; }
};
class F3 : public F1 {
const F2 &f2;
public:
F3() : f2(*new F2) { cout << "F3 ctor "; }
~F3() { cout << "F3 dtor "; }
};
int main() {
F3 f3;
return 0;
}', 'F1 ctor F2 ctor F3 ctor F3 dtor F2 dtor F1 dtor', 'F1 ctor F1 ctor F2 ctor F3 ctor F3 dtor F1 dtor', 'F1 ctor F3 ctor F3 dtor F1 dtor', 'F1 ctor F1 ctor F2 ctor F3 ctor F3 dtor F2 dtor F1 dtor F1 dtor', 'F1 ctor F1 ctor F2 ctor F3 ctor F3 dtor F1 dtor', 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (38, '#include<iostream>
using namespace std;
class Shape {
public:
int x, y;
Shape(int a = 0, int b = 0): x(a), y(b) {}
void draw()
{ cout << x << " " << y << " "; }
};
class Rectangle : public Shape {
public:
int w, h;
Rectangle(int a = 5, int b = 6): w(a), h(b), Shape(7, 8) {}
void draw()
{ Shape::draw(); cout << w << " " << h ; }
};
int main() {
Rectangle *r = new Rectangle(1,2);
r-> draw();
return 0;
}', '0 0 1 2', '7 8 1 2', '7 8 5 6', '0 0 5 6', '7 8 1 2', 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (39, 'Consider the following code snippet:
class Base {
protected:
int marker;
public:
Base(int m = 4) : marker(m) {}
virtual ~Base() {};
virtual void Action() { ++marker; }
};
class Derived : public Base {
public:
void Action() {
static_cast<Base>(*this).Action();
marker *= 2;
cout << marker << endl;
}
};
int main() {
Base *p = new Derived;
p->Action();
return 0;
}
What will be output from the above code?', 8, 10, 4, 32, 8, 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (40, 'Consider the following code snippet:
#include <iostream>
using namespace std;
int fun(int* ptr) {
return (*ptr + 10);
}
int main(void) {
const int val = 10;
const int *ptr = &val;
int *ptr1 = const_cast<int *>(ptr);
cout << fun(ptr1);
return 0;
}
What will be the output of the following program?', 10, 20, 0, 30, 20, 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (41, 'What will be the output of the following program?
#include <cassert>
#include <iostream>
int main() {
int i = 7;
// pointer to integer and back
int* p1 = reinterpret_cast<int*>(&i);
assert(p1 == &i);
// type aliasing through pointer
char* p2 = reinterpret_cast<char*>(&i);
if (p2[0] == ’\x7’)
std::cout << "little-endian\n";
else
std::cout << "big-endian\n";
return 0;
}', 'little-endian', 'big-endian', 'Error: Aliased Type does not satisfy these requirements', 'Error: Accessing the object through the new pointer or reference invokes undefined behavior', 'little-endian', 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (42, 'What will be the output of the following program?
#include <iostream>
#include <typeinfo>
using namespace std;
struct A { virtual ~A() { } };
struct B : A { };
int main() {
B obj;
A* ap = &obj;
A& ar = obj;
cout << typeid(*ap).name();
cout << " " << typeid(ar).name() << endl;
return 0;
}', 'struct A struct B', 'struct A struct A', 'struct B struct B', 'struct B struct A', 'struct B struct B', 'ex');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (43, 'if(5==6==7==0)
cout<<"Hi";
else
cout<<"Bye";
What will be output
(Consider everything included)', 'Hi', 'Bye', 'Hi Bye', 'Error', 'CaughtOne CaughtOne CaughtString CaughtOne', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (44, '#include <iostream>
using namespace std;
class X {
public:
class Trouble {};
class Small : public Trouble {};
class Big : public Trouble {};
void f() { throw Big(); }
};
int main() {
X x;
try {
x.f();
}
catch (X::Trouble&) {
cout << "caught Trouble" << endl;
}
catch (X::Small&) {
cout << "caught Small Trouble" << endl;
}
catch (X::Big&) {
cout << "caught Big Trouble" << endl;
}
catch (...) {
cout << "default" << endl;
}
return 0;
}', 'caught Big Trouble', 'caught Trouble', 'caught Small Trouble', 'default', 'caught Trouble', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (45, 'Which special symbol allowed in a variable name? Marks 1', '* (asterisk)', '| (pipe)', '– (hyphen)', '_ (underscore)', '_ (underscore)', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (46, 'How should the function compute() be defined? Marks 1
int main() {
int a[3][4], b;
b = compute(a,3);
return 0;
}', 'int compute(int p[][n], int row)', 'int compute(int *p[][n], int row)', 'void compute(int *p[m][n], int row)', 'void compute(int p[m][n], int row)', 'int compute(int p[][n], int row)', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (47, 'int main() {
union Data {
int i_;
float f_;
unsigned char str[20];
} data;
printf("size = %d\n", sizeof(data));
data.i_ = 10;
data.f_ = 220.5;
printf( "data.i_ : %d\n", data.i_);
return 0;
}
What value will be printed for data.i?', 10, 220.5, 230.5, 'Unpredictable Value', 'Unpredictable Value', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (48, 'What is the output of the above program? Marks 1
int main() {
int i_ = 3, *j_, k_;
j_ = &i_;
printf("%d\n", i_**j_*i_+*j_);
return 0;
}', 25, 30, 9, 3, 30, '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (49, 'What is the output of the above program? Marks 1
int main() {
int i_ = 5, *j_, k_;
j_ = &i_;
printf("%d\n", i_**j_*i_**j_);
return 0;
}', 625, 125, 5, 'compilation error', 625, '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (50, 'int main() {
int i_ = 5, *j_, k_;
j_ = &i_;
printf("%d\n", i_-*j_*i_-*j_);
return 0;
}', -25, 25, 'invalid operand of type', 'compilation error', -25, '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (51, 'What is the output of the following program ?
int main() {
int sequence[] = {1, 2, 3, 4};
int *pointer = (sequence + 2);
cout << *sequence;
return 0;
}', 1, 3, 4, 'Compilation Error', 1, '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (52, 'Read this program and answer the questions below.
#include <iostream>
#include <cmath>
int main() {
float a, b;
cout << "Input two numbers:\n";
cin >> a >> b;
float sq = sqrt(a*a + b*b);
return 0;
}
What is the compilation error for this program?', 'Each undeclared identifier is reported only once', 'cout and cin not declared in scope', 'invalid conversion from int to float', 'None of the above', 'cout and cin not declared in scope', 'using namespace std');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (53, 'What will be the output of the following program? Marks 1
#include <iostream>
using namespace std;
int main() {
int e1 = 5, e2 = 20, e3 = 15;
int *arr[3] = {&e1, &e2, &e3};
cout << *arr[*arr[1] - 19];
return 0;
}', 5, 20, 15, 'Unpredictable value', 20, '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (54, 'What will be the output of the following program? Marks 1
#include <iostream>
#include <algorithm>
using namespace std;
bool compare (int i, int j) {
return (i > j);
}
int main() {
int data[] = {32, 71, 12, 45, 26};
sort (data, data+4, compare);
for (int i = 0; i < 5; i++)
cout << data[i] << " ";
return 0;
}', '71 45 32 26 12', '71 45 32 12 26', '12 26 32 45 71', 'None of the above', '71 45 32 12 26', '..');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (55, '#include <iostream>
#include <algorithm>
using namespace std;
bool compare (int i, int j) {
return (i > j);
}
int main() {
int data[] = {32, 71, 12, 45, 26};
sort (data, data+0, compare);
for (int i = 0; i < 5; i++)
cout << data[i] << " ";
return 0;
}', '71 45 32 26 12', '32 71 12 45 26', '32 71 12 26 45', 'None of the above', '32 71 12 26 45', '.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (56, 'What will be the output of the following program? Marks 2
#include<iostream>
#include<string.h>
#include<stack>
using namespace std;
int main() {
char str[10]= "ABCDE";
stack<char> s;
for(int i = 0; i < strlen(str); i++)
s.push(str[i]);
for(int i = 0; i < strlen(str) - 1; i++) {
s.pop();
cout << s.top();
}
return 0;
}', 'EDCBA', 'ABCDE', 'ABCD', 'DCBA', 'DCBA', '..');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (57, '#include <stdio.h>
#include <math.h>
int main ()
{
printf ( "%f\n", fmod (5.3,2)%2);
return 0;
}', 1.3000000, 1.300000000, 'Error', 0, 'Error', 'a');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (58, 'Q.1What happens when a null pointer is converted into bool?', 'An error is flagged', 'bool value evaluates to true', 'bool value evaluates to false', 'the statement is ignored', 'bool value evaluates to false', 'Explanation: A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zerovalued pointer converts to false.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (59, '#include <iostream>
using namespace std;
int main()
{
int x = -1;
unsigned int y = 2;
if(x > y) {
cout << "x is greater";
} else {
cout << "y is greater";
}
}', 'x is greater', 'y is greater', 'Implementation defined', 'Arbitrary', 'x is greater.', 'Explanation: x is promoted to unsigned int on comparison. On conversion x has all bits set, making it the bigger one.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (60, 'What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7;
x = x >> 7;', 1, -1, 127, 'Implementation defined', 'Implementation defined', 'Explanation: Right shift of signed integers is undefined, and has implementation-defined behaviour.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (61, '#include <iostream>
using namespace std;
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
}', 'compile time error', '-1 1', '1 -1', 'implementation defined', '-1 1', 'Explanation: Sign of result of mod operation on negative numbers is sign of the dividend.');
INSERT INTO main.comp_questions (id, question, option1, option2, option3, option4, answer, explanation) VALUES (62, 'What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
void a = 10, b = 10;
int c;
c = a + b;
cout << c;
return 0;
}', 20, 'compile time error', 'runtime error', 'none of the mentioned', 'compile time error', 'Explanation:void will not accept any values to its type.');