C++ MCQ
C++ MCQ
int Test::i;
int main()
{
cout << sizeof(Test);
return 0;
3 8 }</pre>
<pre>
#include<iostream>
class Base2 {
public:
Base2()
{ cout << "Base2's constructor called" << endl; }
};
int main()
{
Derived d;
return 0;
}
3 8 </pre>
<pre>
#include<iostream>
using namespace std;
class base {
int arr[10];
};
int main(void)
{
cout<<sizeof(derived);
getchar();
return 0;
}
3 8 </pre>
<pre>
#include<iostream>
using namespace std;
class base {
int arr[10];
};
int main(void)
{
cout<<sizeof(derived);
getchar();
return 0;
</pre>
3 8
<pre>
#include<iostream>
#include<stdio.h>
using namespace std;
class Base
{
public:
Base()
{
fun(); //note: fun() is virtual
}
virtual void fun()
{
cout<<"\nBase Function";
}
};
int main()
{
Base* pBase = new Derived();
delete pBase;
return 0;
3 8 }</pre>
<pre>
#include<iostream>
using namespace std;
int x = 10;
void fun()
{
int x = 2;
{
int x = 1;
cout << ::x << endl;
}
}
int main()
{
fun();
return 0;
}
3 8 </pre>
<pre>
#include <iostream>
int main( ) {
char sample[] = "GeeksforGeeks";
cout << sample << " - A computer science portal for geeks";
return 0;
}
3 9 </pre>
<pre>
#include<iostream>
using namespace std;
int main()
{
int age;
<pre>#include <iostream>
int main( )
{
cerr << "An error occured";
return 0;
}
3 9 </pre>
<pre>#include <iostream>
using namespace std;
int main( )
{
clog << "An error occured";
return 0;
}
3 9 </pre>
3 9 Which header file is used with input and output operations of C in C++?
3 9 Which will be used with physical devices to interact from C++ program
3 9 What is the benefit of c++ input and output over c input and output?
3 10 Which best describes a variable?
3 10 Which of the following is false?
3 10 To use the value of a variable you need to know:
3 10 Which of the following data types CANNOT store the number 47,255?
3 10 In C++ the syntax to declare a variable is:
3 10 Which holds integers or real numbers with 8 bytes of memory allocated?
3 10 Which holds alphanumerics using character encoding? (size varies)
3 10 Which holds whole numbers? (4 bytes)
3 11 What is the size of wchar_t in C++
3 11 Pick the odd one out
3 11 Which datatype is used to represent the absence of parameters?
3 11 What does a escape code represent?
3 11 Which type is best suited to represent the logical values?
3 11 Identify the user-defined types from the following?
Which of the following statements are true?
3 11 int f(float)
3 11 The value 132.54 can represented using which data type?
3 12 Which operator is having right to lef associativity in the following?
3 12 Which operator is having the highest precedence?
3 12 What is this operator called ?: ?
<pre>
Consider the following code:
var i = 0;
while (i < 3) {
println("hi");
i++;
}
println("bye");</pre>
3 17 <b>What does the code output?</b>
<pre>
Consider the following code:
var i = 0;
while (i < 0) {
println("hi");
}</pre>
3 17 <b>What does the code output?</b>
<pre>
Consider the following code:
var x = 3;
var i = 0;
while (i < 3) {
x += 1;
i += 1;
}
println(x);</pre>
3 17 <b>What does the code output?</b>
<pre>
Consider the following code:
var i = 3;
while (i < 6) {
println(i);
i += 1;
}</pre>
3 17 <b>What does the code output?</b>
<pre>
Consider the following code:
var i = 0;
while (i < 3) {
println(i);
i++;
}</pre>
3 17 <b>What does the code output?</b>
out.println(m);
3 18 }</pre>
total=total+s;
3 18 out.println(total);</pre>
What is the output?
while(z<9)
z++;
sum=sum+z;
3 18 System.out.print(sum);</pre>
String s="";
while(k>-1){
s=k+" "+s;
k--;
3 18 System.out.print(s);</pre>
<b>What is the output?</b>
<pre>
int b=5;
String list="";
while(b<11)
b=b+2;
if(b%2==1)
list=b+" "+list;
3 18 System.out.print(list);</pre>
do{
x++;
System.out.print(x);
3 18 }while(x<5);</pre>
do{
tot=tot+k;
k++;
}while(k<11);
3 18 System.out.print(tot);</pre>
3 19 The break statement is used in
3 19 The statements that causes the control program to jump over the other state
3 19 Destination is specified by a label within the statement, is called
3 19 Which from the following is a jumping statement?
An error that causes the program to terminate immediately without having
3 19 successfully performed its job, is called
3 19 An object whose value cannot be changed is called
3 19 In 1977, Apple Computer popularized the phenomenon of
3 19 Keywords are also called
3 19 Which keyword can be used for coming out of recursion?
3 19 The keyword ‘break’ cannot be simply used within:
only 3 ,4
derived data types
Only 5
hardware objects
procedural language
economics
windows
customized array
Int
Void
Double
1
every object of the class is created.
protected
0
Iterators
per = total/(float)m
Compile time
4
Base1's constructor called
Base2's constructor called
Derived's constructor called
56
79
Base Function
11
An error occured
An error occurred
stdio.h
Programs
Type safety
Variables store program data while code runs
Variable values can change while a program runs
The size of the memory used by its data type
double
bool lives;
int
bool
String
2
array type
int
alert
integer
enumeration
f is a function taking an argument of type int and retruning a floating point number
double
Array subscripting
postfix
conditional
35
It converts virtual base class to derived class
6
749736
1000
56
1
&
1
if expression
curly braces
yes
cases can't have conditions
cases must be capitalized
1
for
for
for {i=0,i<10,i++}
for
for (i=0; i<5; i++)
yes
for
do {//code}while (condition);
hi
hi
hi
bye
3
3
4
5
1
2
3
-2
105
42
0 1 2 3
1197
2 3 4 5
52
For loop
Jump statement
While loop
Break statement
Syntax error
Variable
Digital computing
Preprocessors
break
do-while
14
Compilation error
123
1
comments are parts of the source code disregarded by the compiler
single line
hello world
/* …. */
distinguishes between comments and code
It will not return value to its caller
prototype
after int main()
double
int
int
double
subtract (x)
global variable
yes
1
static
call by value
2 5 10
10
6
100
11
It will not return value to its caller
Larger instances of different problems
Factorial of a number
Switch Case
Best case
return
9
Recursion is always better than iteration
auto
The time during which identifier exists in memory
2
auto
A2
const
procedural
Functions
Virtual Functions
No
<string>
<string>
The second input overwrites the first one
The program worked as expected without any errors during its execution
default
long int
template< typename T> return_type Function_Name(parameters
Object Association
Its virtual nature will be lost
only 1,3,5
User defined data types
Only 1 and 4
graphic objects
Object oriented language
transport
matlab software
stack
MyMethod
ShowMenu
Value
False
Run time
3
Base1's constructor called
55
80
None
12
54
cstdio
Library
Exception
Variables control memory space
Variables make it possible to process almost any kind of data
The source of the data being stored
int
integer intScore;
double
int
bool
4
character type
short
backslash
boolean
classes
20
it converts virtual base object to derived objeccts
5
736749
11
65
66
&&
0
if { expression
scanf
no
cases must be capitalized
cases must have ; not :
0
have
do
for (i=0; i<10; i++);
do
for (i=5; i<=10; i++)
no
do
do {//code}while (condition)
hi
hi
hi
None
7
1
2
3
0
1
2
3
104
54
2 3 4 5
1 0 9 7
2314
55
Foreach loop
Goto statement
Goto statement
Continue statement
Fatal error
Constant
Personal computing
Reserved words
return
if-else
To stop the current iteration and begin the next iteration
from the beginning
+
To stop the current iteration and begin the next iteration
from the beginning
malloc.h
stdio.h
read a character from a file
Initialization in for loop
Infinite loop
Compilation error
123
13
2
comments are executed by compiler to find the meaning of the comment
multi line
hello
/$ …. $/
r distinguishes between comments and outer data
It will return value to its caller
declare
before int main()
int x
double
double
int & double
subtract (y)
local variable
no
2
const
call by reference
245
20
24
The code will be executed successfully and random output will be genera
1
printf(“%d “, n)
10
Recursion uses more memory compared to iteration
register
Which function is to use
3
register
A3
#define
bottom-up
Objects
Templates
<sstring>
<sstring>
The second input attempt fails since the variable already g
not to end the program yet.
readable
short int
both a and b
Containership
both a and b
2,4,5
built-in data types
binary tree
String
1
Both a and b
2
Base2's constructor called
54
81
Base Function and Base
13
GeeksforGeeks
16
15
85
iostream
Streams
Both Type safety & Exception
Variables are individual values in a database table
All variables use the same amount of memory
The physical address location in memory
String
char Broiled;
bool
decimal
int
2 or 4
boolean type
void
tab
character
both enumeration and classes
25
it will convert the operator based on precedence
4
367497
1010
67
-1
|
Unevaluatable
if ( expression )
break
do
while
for (i=0; i<10; i++)
while
for (i=5; i=10; i++)
while
do {//code}while (condition):
hi
bye
hi
it won't input
6
3
4
5
6
0
1
2
103
24
2 3 4
1 1 9 8
2215
53
Switch Statement
Spaghetti Statement
For loop
Switch statement
Termination error
Operator
Distributed computing
Punctuation marks
exit
for
124
12
132
3
comments are executable
single line and multi line
subtract (x,y)
extended variable
3
absolute
call by pointer
2 6 14
15
segmentation fault
144
13
Maybe or maynot be return any value to its caller
Smaller instances of the same problem
Length of a string
If-else
Base case
if(n == 0)
11
Recursion uses less memory compared to iteration
extern
Where to store program
4
static
A4 A
All of these 4
all of these. 3
Data types 3
None of these 3
1
<sstream> 1
<sstream> 4
You can not use same variable for two getline statements 2
None of above 2
volatile 3
float 3
None of these 3
None of these 3
Compiler will generate “Prototype mismatch error” 3
Only 2,3 4
All of these 2
Only 2 and 5 4
circuit designing objects 2
JAVA 1
country 4
joystick 1
decimal tree
3
Double 4
Category 4
2 1
1
No need to initialize static variable. 3
static 2
Compiler dependent 1
Allocators 3
None of these 2
None of these 2
1 1
Derived's constructor called 1
53 1
82 2
Based 1
10 4
None
1
15 1
42 1
74 1
30 2
none of the mentioned 1
7 1
none of the mentioned 1
1001 3
hi
hi
bye
hi
1
all 1
4 3
1
5 1
102 1
44 1
45 6 1
1 0 1 6 1
2323 1
54 1
None of them 3
None of them 1
Foreach loop 2
All of them 4
Both B and C
2
None of them 2
Client/server computing 2
Operators 2
Both break and return 2
while 2
None of above
2
- 3
None of above
2
None of above 1
stdoutput.h 2
read file random 2
All of them 1
None of them 1
134 1
13 2
Compilation error 4
4 2
none of the mentioned 1
none of the mentioned 3
3
2
1
4 3
none of the mentioned 2
none of the mentioned 1
110 4
compile time error 3
None of the mentioned 1
Smaller instances of different problems 3
All of the mentioned 4
None of the mentioned 2
There is no such condition 3
The code will run for some time and stop when the stack overflows 4
10 9 8 … 1 4
my_recursive_function(n-1) 3
12 3
Iteration is always better and simpler than recursion 2
mat 4
None of them 1
5 4
volatile 4