C++ MOCK TEST
http://www.tutorialspoint.com Copyright © tutorialspoint.com
This section presents you various set of Mock Tests related to C++ Framework. You can
download these sample mock tests at your local machine and solve offline at your convenience.
Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
C++ MOCK TEST IV
Q 1 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
float t = 2;
switch(t)
{
case 2: cout<<”Hi”;
default: cout<<"Hello";
}
}
A - Hi
B - HiHello
C - Hello
D - Error
Q 2 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
int a[] = {1, 2}, *p = a;
cout<<p[1];
}
A-1
B-2
C - Compile error
D - Runtime error
Q 3 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
int i = 13, j = 60;
i^=j;
j^=i;
i^=j;
cout<<i<<” “<<j;
}
A - 73 73
B - 60 13
C - 13 60
D - 60 60
Q 4 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
union abc {
int x;
char ch;
} var;
var.ch = 'A';
cout<<var.x;
}
A-A
B - Garbage value
C - 65
D - 97
Q 5 - Compiler generates ___ file
A - Executable code
B - Object code
C - Assembly code
D - None of the above.
Q 6 - Special symbol permitted with in the identifier name.
A-$
B-@
C-_
D-.
Q 7 - A single line comment in C++ language source code can begin with _____
A-;
B-:
C - /*
D - //
Q 8 - An inline function can execute faster than a normal function.
A - True
B - False
Q 9 - Choose the invalid identifier from the below
A - Int
B - bool
C - DOUBLE
D - __0__
Q 10 - Identify the C++ compiler of Linux
A - cpp
B - g++
C - Borland
D - vc++
Q 11 - Following is the invalid inclusion of a file to the current program. Identify it
A - #include <file>
C - #include < file
D - All of the above are invalid
Q 12 - What is the output of the following program?
#include<isotream>
using namespace std;
int x = 5;
int& f() {
return x;
}
main() {
f() = 10;
cout<<x;
}
A-5
B - Address of ‘x’
C - Compile error
D - 10
Q 13 - The default executable generation on UNIX for a C++ program is ___
A - a.exe
B-a
C - a.out
D - out.a
Q 14 - What is the output of the following program?
#include<isotream>
using namespace std;
void f() {
static int i = 3;
cout<<i;
if(--i) f();
}
main() {
f();
}
A-3210
B-321
C-333
D - Compile error
Q 15 - What is the output of the following program?
main() {
}
A - No output
B - Garbage
C - Compile error
D - Runtime error
Q 16 - Does both the loops in the following programs prints the correct string length?
#include<isotream>
using namespace std;
main()
{
int i;
char s[] = "hello";
for(i=0; s[i]; ++i);
cout<<i<<endl;
i=0;
while(s[i++]);
cout<<i;
}
A - Yes, both the loops prints the correct length
B - Only for loop prints the correct length
C - Only while loop prints the correct length
D - Compile error in the program.
Q 17 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
int a[] = {10, 20, 30};
cout<<*a+1;
}
A - 10
B - 20
C - 11
D - 21
Q 18 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
char s[] = "Fine";
*s = 'N';
cout<<s<<endl;
}
A - Fine
B - Nine
C - Compile error
D - Runtime error
Q 19 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
char *s = "Fine";
*s = 'N';
cout<<s<<endl;
}
A - Fine
B - Nine
C - Compile error
D - Runtime error
Q 20 - What is the built in library function to compare two strings?
A - string_cmp
B - strcmp
C - equals
D - str_compare
Q 21 - What is the output of the following program?
#include<isotream>
using namespace std;
void main()
{
char *s = "C++";
cout<<s<<" ";
s++;
cout<<s<<" ";
}
A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error
Q 22 - What is the output of the following program?
#include<isotream>
using namespace std;
void main()
{
char s[] = "C++";
cout<<s<<" ";
s++;
cout<<s<<" ";
}
A - C++ C++
B - C++ ++
C - ++ ++
D - Compile error
Q 23 - What is the output of the following program?
#include<isotream>
#include<string.h>
using namespace std;
main()
{
char s[]="Hello\0Hi";
Cout<<strlen(s)<<” “<<sizeof(s);
}
A-59
B - 7 20
C - 5 20
D - 8 20
Q 24 - What is the output of the following program?
#include<isotream>
using namespace std;
main()
{
class student
{
int rno = 10;
} v;
cout<<v.rno;
}
A - 10
B - Garbage
C - Runtime error
D - Compile error
Q 25 - i) Exceptions can be traced and controlled using conditional statements.
ii) For critical exceptions compiler provides the handler
A - Only i is true
B - Only ii is true
C - Both i & ii are true
D - Both i && ii are false
ANSWER SHEET
Question Number Answer Key
1 D
2 B
3 B
4 C
5 B
6 C
7 D
8 A
9 B
10 B
11 C
12 D
13 C
14 B
15 A
16 B
17 C
18 B
19 D
20 B
21 B
22 D
23 A
24 D
25 B
Loading [MathJax]/jax/output/HTML-CSS/jax.js