C++ MCQ with Answers
C++ is a general-purpose programming language. It was designed and implemented by Bjarne Stroustrup in 1979 at Bell Labs. It runs on a variety of platforms, such as Windows, MacOS, and the various versions of UNIX. C++ is
- A superset of C
- Supports data abstraction
- Supports object-oriented programming
- Supports generic programming.
Types: Types are fundamental to any program.
C++ has extensive support for types:
- Primitive types(characters, integers, floating-point numbers, etc.)- Defined by the language itself.
- User-defined types - Provides mechanisms that let us define our own data types.
Primitive Types can be divided into two types:
- Arithmetic Type -
- Integral Types(Characters, integers, boolean values, etc)
- Floating-point types(float, double, etc)
- Void(special type)
Variables: A variable provides us with named storage that our programs can manipulate.
Each variable in C++ has a type. It determines the size and layout of the variable’s memory.
It also determines the range of values that can be stored within that memory along with the set of operations that can be applied to the variable. A simple variable definition consists of:
- A type specifier.
- A list of one or more variable names separated by commas, and ends with a semicolon.
Classes and Objects in C++:
- Class is a description of an object.
- An object is an instance of a class
Instance member variable: Attributes, data members, field, properties.
Instance member functions: Methods, procedures, actions, operations, services.
Access Specifier: There are three types of access specifiers in class:
- Private
- Public
- Protected
Features of OOPS: There are primarily four pillars of OOPS:
- Data abstraction: Data hiding
- Inheritance: Reusability
- Polymorphism: Object to take many forms
- Encapsulation: Data hiding
C++ MCQ
What is an object in c++?
It is function of class
It is instance of class
It is datatype of class
It is part of the syntax of class
Identify the incorrect constructor type.
Friend constructor
Default constructor
Parameterized constructor
Copy constructor
Identify the logical AND operator.
||
&&
&
!
Identify the scope resolution operator.
:
::
?
None
Identify the size of int datatype in C++.
1 byte
2 bytes
4 bytes
Depends on compiler
Identify the storage classes that have global visibility.
extern
auto
register
static
Size of wchat_t is.
2
4
2 or 4
Depends on number of bits in system
The constants in C++ are also known as?
pre-processor
literals
const
none
Total types of constructors in C++ are?
1
2
3
4
Total types of errors in C++.
1
2
3
4
Under which pillar of OOPS does base class and derived class relationship come?
Polymorphism
Inheritance
Encapsulation
Abstraction
Using which of the following data type can 19.54 be represented?
void
double
int
None
Using which of the following keywords can an exception be generated?
threw
throws
throw
catch
What does a C++ class hold?
Function
Data
Arrays
Both a and b
Identify the format string among the following.
&
\n
%d
None
What is do-while loop also known as?
Exit control
Entry control
Per tested
All of the above
What is the ASCII value of ‘\0’ character?
32
24
48
0
What is the number of parameters that a default constructor requires?
0
1
2
3
When can an inline function be expanded?
Runtime
Compile time
Never gets expanded
All of the above
Which of the following data type is supported in C++ but not in C?
int
bool
double
float
Which of the following functions can be inherited from base class?
Constructor
Destructor
Static
None
Which of the following is not a type of inheritance?
Multiple
Multilevel
Distributed
Heirarchical
Which of the following is the correct identifier?
2var_name
2VAR_NAME
$varname
var_name12
Which of the following is “address of operator”?.
*
&
[]
&&
Which of the following loops is best when we know the number of iterations?
While loop
Do while
For loop
All of the above
Which of the following types is the language C++?
Procedural
Statically typed language
Dynamically typed language
All of the above
Why are comments used?
Make the program run faster
To help others read & understand the program
Increase the size of the executable program
Make a program compile easier
Find the output of the following program.
main(){
char ch[] = “Interviewbit Scaler”;
int l = strlen(ch);
cout << l << endl;
}
18
19
20
21
C++ uses which approach?
right -left
Top-down
left-right
bottom -up
Choose the correct default return value of function.
int
void
char
float
Choose the correct option which is mandatory in a function.
return_type
parameters
function_name
Both a and c
Choose the correct subscript operator.
[ ]
{ }
*
( )
Choose the option below which is not a member of class.
Friend function
Static function
Virtual function
Const function
Choose the size of the below struct.
Struct{
Int a;
Char b;
Float c;
}
2
4
7
10
Choose the type of loop which is guaranteed to execute at-least once?
for loop
do-while
while
None
Data members and member functions of a class are private by.default. True or False?
True
False
Depends on code
None
Find the output of the following program.
main(){
int i = (1, 2, 3);
cout << i << endl;
}
1
2
3
Error
Find the output of the following program.
main(){
int a, b = 10;
a = 95 / 10;
cout << a << endl;
}
9
9.5
10
9.0
Find the output of the following program.
main(){
int a = 10 / 0;
}
0
Compilation error
exception
None
Find the output of the following program.
main(){
int a = 10, b, c;
b = a++;
c = a;
cout << a << “ “ <<b <<” “<< c << endl;
}
10 11 11
11 11 11
11 10 11
10 10 10
By which of the following can the if-else statement be replaced?
Bitwise operator
Logical operator
Conditional operator
Arithmetic operator
Find the output of the following program.
main(){
cout << -10 - 10 -10;
}
0
-30
30
20
Find the output of the following program.
main(){
Float a = 5;
switch(a){
Case 5: cout <<”Interviewbit”;
Default: cout <<”Scaler”;
}
}
Interviewbit
Scaler
InterviewbitScaler
Error
goto can be classified into?
label
variable
operator
function
How many times will the print statement be executed?
main(){
int i = 0;
label:
cout << “Interviewbit;
i++;
if(i < 3){
goto label;
}
}
1 time
2 times
3 times
Error
How much bytes of memory does void occupy?
1
0
2
4
Identify the correct definition of ‘*’ operator in pointer.
Address of operator
Value of address operator
Multiplication operator
All of the above
Identify the correct escape sequence used for the new line.
\t
\n
\a
None
Identify the correct example for a pre-increment operator.
++n
n++
- -n
+n
Identify the correct extension of the user-defined header file in C++.
.cpp
.hg
.h
.hf
Identify the correct function from which the execution of C++ program starts?
new()
start()
pow()
main()
Identify the correct range of signed char.
-256 to 255
-128 to 127
0 to 255
0 to 127
Identify the correct syntax for declaring arrays in C++.
array arr[10]
array{10}
int arr[10]
int arr