0% found this document useful (0 votes)
30 views8 pages

C Mock Exam 3

The document contains 25 multiple choice questions about C++ concepts like constructors, arrays, comments, inheritance, classes, exception handling, I/O streams, and data types. It also provides the answers to each question in a table at the end.

Uploaded by

Roshane Phillips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views8 pages

C Mock Exam 3

The document contains 25 multiple choice questions about C++ concepts like constructors, arrays, comments, inheritance, classes, exception handling, I/O streams, and data types. It also provides the answers to each question in a table at the end.

Uploaded by

Roshane Phillips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

C++ Mock Test III

Q 1 - Choose the option not applicable for the constructor.


A - Cannot be called explicitly. B - Cannot be overloaded.
C - Cannot be overridden. D - None of the above.

Q 2 - An array can be passed to the function with call by value mechanism.
A - True B - False

Q 3 - A C++ program statements can be commented using


A - Single line comment B - Multi line comment C - Either (a) or (b) D - Both (a) and
(b).

Q 4 - HAS-A relationship between the classes is shown through.


A - Inheritance B - Container classes C - Polymorphism D - None of the above.

Q 5 - What is a generic class.


A - Function template B - Class template B - Inherited class B - None of the above.

Q 6 - What is the full form of STL?


A - Standard template library. B - System template library.
C - Standard topics library. D - None of the above.

Q 7 - Which type of data file is analogous to an audio cassette tape?


A - Random access file B - Sequential access file C - Binary file D - Source code file

Q 8 - i) single file can be opened by several streams simultaneously.


ii) several files simultaneously can be opened by a single stream
A - (i) and (ii) are true B - (i) and (ii) are false C - Only (i) is true D - Only (ii) is true

Q 9 - With respective to streams >> (operator) is called as


A - Insertion operator B - Extraction operator
C - Right shift operator D - Left shift operator

1
Q 10 - (i) ‘ios’ is the base class of ‘istream’
(ii) All the files are classified into only 2 types. (1) Text Files (2) Binary Files.
A - Only (i) is true B - Only (ii) is true C - Both (i) & (ii) are true D - Both (i) & (ii) are false

Q 11 - An exception is __
A - Runtime error B - Compile time error C - Logical error D - None of the above

Q 12 - i) Exception handling technically provides multi branching.


ii) Exception handling can be mimicked using ‘goto’ construct.
A - Only (i) is true B - Only (ii) is true
C - Both (i) & (ii) are true D - Both (i) && (ii) are false

Q 13 - What is the output of the following program?

#include<iostream>
using namespace std;
main() {
const int a = 5;

a++;
cout<<a;
}
A - 5 B - 6 C - Runtime error D - Compile error

Q 14 - What is the output of the following program?

#include<iostream>
using namespace std;
main() {
char s[] = "hello", t[] = "hello";
if(s==t)
cout<<"eqaul strings";
}
A - Equal strings B - Unequal strings C - No output D - Compilation error

2
Q 15 - What is the outpout of the following program?

#include<iostream>
using namespace std;
main() {
enum {
india, is = 7, GREAT
};
cout<<india<<" "<<GREAT;
}
A - 0 1 B - 0 2 C - 0 8 D - Compile error

Q 16 - What is the output of the following program?

#include<iostream>
using namespace std;
main() {
short unsigned int i = 0;

cout<<i--;
}
A - 0 B - Compile error C - 65535 D - 32767

Q 17 - What is the output of the following program?

#include<iostream>
using namespace std;
main() {
int x = 5;
if(x==5) {
if(x==5) break;
cout<<"Hello";
}
cout<<”Hi”;
}
A - Compile error B - Hi C - HelloHi D - Hello

3
Q 18 - What is the output of the following program?

#include<iostream>
using namespace std;
void f() {
static int i;
++i;
cout<<i<<" ";
}
main() {
f();
f();
f();
}
A - 1 1 1 B - 0 0 0 C - 3 2 1 D - 1 2 3

Q 19 - What is the output of the following program?

#include<iostream>
using namespace std;
void f() {
cout<<"Hello"<<endl;
}
main() {
}
A - No output
B - Error, as the function is not called.
C - Error, as the function is defined without its declaration
D - Error, as the main() function is left empty

4
Q 20 - What is the output of the following program?
#include <iostream>
using namespace std;
int main () {
// local variable declaration:
int x = 1;
switch(x) {
case 1 :
cout << "Hi!" << endl;
break;
default :
cout << "Hello!" << endl;
}
}
A - Hello B - Hi C - HelloHi D - Compile error

Q 21 - What is the output of the following program?


#include<iostream>
using namespace std;
void swap(int m, int n) {
int x = m;
m = n;
n = x;
}
main() {
int x = 5, y = 3;
swap(x,y);
cout<<x<<" "<<y;
}
A - 3 5 B - 5 3 C - 5 5 D - Compile error

Q 22 - What will be the output of the following program?


#include<iostream>
#include<string.h>
using namespace std;
main() {
cout<<strcmp("strcmp()","strcmp()");
}
A - 0 B - 1 C - -1 D - Invalid use of strcmp() function

5
Q 23 - What is the output of the following program?

#include<iostream>
using namespace std;
main() {
int r, x = 2;
float y = 5;
r = y%x;
cout<<r;
}
A - 1 B - 0 C - 2 D - Compile error

Q 24 - What is the size of the following union definition?

#include<iostream>
using namespace std;
main() {
union abc {
char a, b, c, d, e, f, g, h;
int i;
};
cout<<sizeof(abc);
}
A - 1 B - 2 C - 4 D - 8

Q 25 - What is the size of ‘int’?


A - 2 B - 4 C - 8 D - Compiler dependent

6
Question Number Answer Key

7
1 C

2 B

3 D

4 B

5 B

6 A

7 B

8 C

9 B

10 C

11 A

12 A

13 D

14 C

15 C

16 A

17 A

18 D

19 A

20 B

21 B

22 A

23 D

24 C

25 D

You might also like