Google News
logo
CPP - Quiz(MCQ)
A)
-1
B)
1
C)
0
D)
Programs do not return a value.

Correct Answer : Option (C) :   0

A)
main()
B)
start()
C)
system()
D)
program()

Correct Answer : Option (A) :   main()

A)
( and )
B)
{ }
C)
->
D)
BEGIN and END

Correct Answer : Option (B) :   { }

A)
' (single quote)
B)
" (double quote)
C)
: (colon)
D)
; (semi-colon)

Correct Answer : Option (D) :   ; (semi-colon)

A)
{ Comment }
B)
** Comment **
C)
*/ Comments */
D)
/* Comment */

Correct Answer : Option (D) :   /* Comment */

A)
int
B)
double
C)
real
D)
float

Correct Answer : Option (C) :   real

A)
=
B)
==
C)
:=
D)
equal

Correct Answer : Option (B) :   ==

A)
!
B)
_
C)
@
D)
$

Correct Answer : Option (B) :   _


Explanation : The only permitted special symbol is under score (_) in the identifier.

9 .
What is the output of the following program?

#include<iostream>

using namespace std;
main() { 
   int a[] = {1, 2}, *p = a;
   
   cout<<p[1]; 
}​
A)
1
B)
2
C)
Runtime error
D)
Compile error

Correct Answer : Option (B) :   2


Explaination : as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

10 .
What is the output of the following program in C++?

#include

using namespace std;
main() {
   short unsigned int i = 0; 
   
   cout<<i--;
}​
A)
Zero (0)
B)
32767
C)
65535
D)
Compile error

Correct Answer : Option (A) :   Zero (0)


Explaination : 0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented

A)
Abstraction
B)
Encapsulation
C)
Polymorphism
D)
Inheritance

Correct Answer : Option (D) :   Inheritance


Explanation : The process of designing a new class (derived) from the existing (base) class to acquire the attributes of the existing is called as inheritance. Inheritance gives the concept of reusability for code/software components.

A)
Bjarne Stroutstrup
B)
Thomas Kushz
C)
James Goling
D)
John Kemney

Correct Answer : Option (A) :   Bjarne Stroutstrup


Explanation : Before the initial standardization in 1998, C++ was developed by Danish computer scientist Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C language; he wanted an efficient and flexible language similar to C that also provided high-level features for program organization.

A)
Key
B)
Jump
C)
Switch
D)
Size

Correct Answer : Option (C) :   Switch

A)
Comma
B)
Dot
C)
Colon
D)
Semicolon

Correct Answer : Option (A) :   Comma

A)
Comma
B)
Logical
C)
Equality
D)
Class member

Correct Answer : Option (B) :   Logical


Explanation : The logical AND ( && ) operator (logical conjunction) for a set of operands is true if and only if all of its operands are true. It is typically used with Boolean (logical) values. When it is, it returns a Boolean value.

A)
#include [userdefined]
B)
#include <userdefined>
C)
#include <userdefined.h>
D)
#include “userdefined”

Correct Answer : Option (D) :   #include “userdefined”


Explanation : C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.

A)
Overloaded
B)
Extensible
C)
Reprehensible
D)
Encapsulated

Correct Answer : Option (B) :   Extensible


Explanation : Languages that can produce/generate new data types are called extensible languages as they have the ability to handle new data types.

A)
$var_name
B)
7var_name
C)
7VARNAME
D)
VAR_1234

Correct Answer : Option (D) :   VAR_1234


Explanation :

The rules for writing an identifier is as follows :

i) may contain lowercase/uppercase letters, digits or underscore(_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.

A)
&
B)
%
C)
*
D)
@

Correct Answer : Option (A) :   &


Explanation : & operator is called address operator and is used to access the address of a variable.

A)
>
B)
<
C)
>>
D)
<<

Correct Answer : Option (C) :   >>


Explanation : >> operator is called extraction or get from operator i.e. extract/get things from console/files.

A)
\a
B)
\b
C)
\t
D)
\t\r

Correct Answer : Option (C) :   \t


Explanation : is used to represent tab which means a set of blank spaces in a line.

A)
Variables that are never used in the function
B)
Parameters with which functions are called
C)
Variables other than passed parameters in a function
D)
Parameters which are used in the definition of a function

Correct Answer : Option (B) :   Parameters with which functions are called


Explanation : Actual parameters are those using which a function call is made i.e. which are actually passed in a function when that function is called.

A)
Set of characters that are used in the name of the main function of the program
B)
Set of characters that whose use are avoided in C++ programs
C)
Set of characters that are avoided in cout statements
D)
Set of characters that convey special meaning in a program

Correct Answer : Option (D) :   Set of characters that convey special meaning in a program


Explanation : Escape sequence is a set of characters that convey a special meaning to the program. They are used to convey a meaning which cannot be conveyed directly.

A)
Parameters which are used in the definition of the function
B)
Variables that are never used in the function
C)
Parameters with which functions are called
D)
Variables other than passed parameters in a function

Correct Answer : Option (A) :   Parameters which are used in the definition of the function


Explanation : Formal parameters are those which are used in the definition of a function. They are the parameters that represent the actual parameters passed and they are the one which is used inside the function.

A)
cout.putline(ch)
B)
cout.put(ch)
C)
printf(ch)
D)
write(ch)

Correct Answer : Option (B) :   cout.put(ch)


Explanation : C++ provides cout.put() function to write a single character to console whereas others are used to write either a single or multiple characters.

A)
scanf(ch)
B)
read(ch)
C)
cin.get(ch)
D)
getline(ch)

Correct Answer : Option (C) :   cin.get(ch)


Explanation : C++ provides cin.get() function to read a single character from console whereas others are used to read either a single or multiple characters.

A)
Both are available in C
B)
Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call
C)
Pointer object initialization of a class with both new and malloc calls the constructor of that class
D)
Pointer object initialization of a class using malloc involves constructor call whereas using new does not involve constructor call

Correct Answer : Option (B) :   Pointer object initialization of a class using new involves constructor call whereas using malloc does not involve constructor call


Explanation : Object initialization using new keyword involves constructor call whereas malloc does not involve constructor call. That’s why new is explicitly added in C++. Also, malloc is used to assign memory to any pointer hence it assigns memory equals to the size of the class however new keyword involves initialization also hence calls the constructor of that class.

A)
Member functions
B)
Class
C)
Destructors
D)
Constructors

Correct Answer : Option (D) :   Constructors


Explanation : Virtual keyword cannot be used with constructors as constructors are defined to initialized an object of particular class hence no other class needs constructor of other class.

A)
Singleton class
B)
Abstract class
C)
Virtual class
D)
None of the above

Correct Answer : Option (A) :   Singleton class


Explanation : Singleton class allows the programmer to declare only one object of it, If one tries to declare more than one object the program results into error.

A)
Encapsulation
B)
Polymorphism
C)
Modularity
D)
Abstraction

Correct Answer : Option (A) :   Encapsulation


Explanation : In OOPs, the property of enclosing data and its related functions into a single entity(in C++ we call them classes) is called encapsulation.

A)
delete is a keyword whereas delete[ ] is an identifier
B)
delete is used to delete normal objects whereas delete[ ] is used to pointer objects
C)
delete is used to delete single object whereas delete[ ] is used to multiple(array/pointer of) objects
D)
delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case

Correct Answer : Option (C) :   delete is used to delete single object whereas delete[ ] is used to multiple(array/pointer of) objects


Explanation : delete is used to delete a single object initiated using new keyword whereas delete[ ] is used to delete a group of objects initiated with the new operator.

A)
C++ technique to enhance multiple inheritance
B)
C++ technique to avoid multiple inheritances of classes
C)
C++ technique to avoid multiple copies of the base class into children/derived class
D)
C++ technique to ensure that a private member of the base class can be accessed somehow

Correct Answer : Option (C) :   C++ technique to avoid multiple copies of the base class into children/derived class


Explanation :

Virtual inheritance is a C++ technique that ensures only one copy of a base class's member variables are inherited by grandchild derived classes. Without virtual inheritance, if two classes B and C inherit from a class A, and a class D inherits from both B and C, then D will contain two copies of A's member variables: one via B, and one via C. These will be accessible independently, using scope resolution.
 
Instead, if classes B and C inherit virtually from class A, then objects of class D will contain only one set of the member variables from class A. etc,. (Refer Wikipedia for more info..)

A)
Constant functions
B)
Virtual functions
C)
Static functions
D)
Operator functions

Correct Answer : Option (B) :   Virtual functions


Explanation : Virtual functions are used to implement the concept of late binding i.e. binding actual functions to their calls.

A)
A reference cannot be made null
B)
A reference cannot be changed once initialized
C)
No extra operator is needed for dereferencing of a reference
D)
All of the mentioned

Correct Answer : Option (D) :   All of the mentioned


Explanation : * References are used to refer an existing variable in another name whereas pointers are used to store address of variable.

* References cannot have a null value assigned but pointer can.

* A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.

* A reference must be initialized on declaration while it is not necessary in case of pointer.
 
* A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack.

A)
Structures by default hide every member whereas classes do not
B)
In Structures, members are public by default whereas, in Classes, they are private by default
C)
Structures cannot have private members whereas classes can have
D)
In Structures, members are private by default whereas, in Classes, they are public by default

Correct Answer : Option (B) :   In Structures, members are public by default whereas, in Classes, they are private by default


Explanation : The only difference between a struct and class in C++ is the default accessibility of member variables and methods. In a struct they are public; in a class they are private.

A)
int **arr = new int*[10];
B)
int *arr = new int[10];
C)
int *arr = new int*[10];
D)
int arr = new int[10];

Correct Answer : Option (A) :   int **arr = new int*[10];


Explanation : As we have to declare an array of pointers of integers therefore we need double pointer array in which each element is collection pointers to integers. Therefore the correct syntax is int **arr = new int*[10];

A)
Templates
B)
Function overloading
C)
Operator overloading
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : All the options mentioned above uses static polymorphism mechanism. As the conflicts in all these types of functions are resolved during compile-time.

A)
Inheritance
B)
Encapsulation
C)
Composition
D)
Abstraction

Correct Answer : Option (C) :   Composition


Explanation : The concept of using objects of one class into another class is known as Composition.

A)
Concept of hiding data
B)
Concept of wrapping things into a single unit
C)
Concept of allowing overiding of functions
D)
Concept of keeping things in differnt modules/files

Correct Answer : Option (C) :   Concept of allowing overiding of functions


Explanation :

* In OOPs, Polymorphism is the concept of allowing a user to override functions either by changing the types or number of parameters passed.
 
* Polymorphism is a feature of object-oriented programming languages that allows a specific routine to use variables of different types at different times
 
* Polymorphism is the ability of a programming language to present the same interface for several different underlying data types

A)
Subdividing program into small independent parts
B)
Wrapping things into single unit
C)
Overriding parts of program
D)
Hiding part of program

Correct Answer : Option (A) :   Subdividing program into small independent parts


Explanation : Modularity means dividing a program into independent sub programs so that it can be invoked from other parts of the same program or any other program.

41 .
Which of the following feature of OOPs is not used in the following C++ code?

class A
{
    int i;
    public:
    void print(){cout<<"hello"<<i;}
}
 
class B: public A
{
    int j;
    public:
    void assign(int a){j = a;}
}​
A)
Inheritance
B)
Polymorphism
C)
Abstraction
D)
Encapsulation

Correct Answer : Option (B) :   Polymorphism

A)
Using Virtual functions
B)
Using Inheritance and Virtual functions
C)
Using Inheritance
D)
Using Templates

Correct Answer : Option (B) :   Using Inheritance and Virtual functions


Explanation : Run-time polymorphism is implemented using Inheritance and virtual in which object decides which function to call.

A)
Transient polymorphism
B)
Pseudo polymorphism
C)
Virtual polymorphism
D)
Ad-hoc polymorphism

Correct Answer : Option (D) :   Ad-hoc polymorphism


Explanation : Ad-hoc polymorphism is a type of polymorphism in which a function denotes heterogeneous implementation depending upon the types of argument.

44 .
What happens if a pointer is deleted twice in a program as shown in the following C++ statements?

int *ptr = new int;
delete ptr;
delete ptr;​
A)
Semantically incorrect
B)
Syntactically incorrect
C)
Undefined behaviour
D)
The program runs perfectly

Correct Answer : Option (C) :   Undefined behaviour

A)
bool
B)
void
C)
int
D)
float

Correct Answer : Option (A) :   bool


Explanation : Boolean type is not present as a fundamental type in C. int type is used as boolean in C whereas in C++ bool is defined as a fundamental type for handling boolean outputs.

46 .
What will be the output of the following C++ code?
#include<iostream>
using namespace std;
int x = 1;
int main()
{
    int x = 2;
    {
        int x = 3;
        cout << ::x << endl;
    }
    return 0;
}​
A)
1
B)
2
C)
3
D)
123

Correct Answer : Option (A) :   1

47 .
What happens if the following code is compiled on both C and C++?
#include<stdio.h>
struct STRUCT
{
private:
	int a;
};
int main()
{
	printf("%d\n", (int)sizeof(struct STRUCT));
	return 0;
}​
A)
The program gives an error in case of C++ but runs perfectly in case of C
B)
The program gives an error in case of both C and C++
C)
The program gives an error in case of C but runs perfectly in case of C++
D)
The program runs fine and both prints output “HELLO THIS IS STRUCTURE”

Correct Answer : Option (C) :   The program gives an error in case of C but runs perfectly in case of C++

A)
1 byte
B)
1 bit
C)
2 bytes
D)
4 bytes

Correct Answer : Option (B) :   1 bit


Explanation : Boolean uses only 1 bit as it stores only truth values which can be true(1) or false(0).

A)
Logical not
B)
addressof
C)
Unary operator
D)
Array element access

Correct Answer : Option (D) :   Array element access


Explanation : Array element has left to right associativity i.e. expressions are evaluated from left to right in case of array element access.

A)
1 and 1
B)
1 and 4
C)
4 and 1
D)
4 and 4

Correct Answer : Option (C) :   4 and 1


Explanation : The size of a character literal is 4 in case of C but it is one in case of C++. You can do printf(“%d”, (int)sizeof(‘a’)); in both C and C++ to check this.

A)
4 and 4
B)
4 and 1
C)
1 and 4
D)
1 and 1

Correct Answer : Option (D) :   1 and 1


Explanation : The size of a character type in both C and C++ is 1. You can do printf(“%d”, (int)sizeof(char)); in both C and C++ to check this.

A)
To access objects of other class
B)
To access objects of other variables
C)
To access all the data stored under that class
D)
To access the members of a class which have the same name as local variables in that scope

Correct Answer : Option (D) :   To access the members of a class which have the same name as local variables in that scope


Explanation : this pointer is used to access the members of a class which have the same name as local variables in that part of the code.

A)
Dynamic polymorphism
B)
Static polymorphism
C)
Executing polymorphism
D)
Non-executing polymorphism

Correct Answer : Option (B) :   Static polymorphism


Explanation : Compile-time polymorphism: It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator overloading.

A)
Dynamic polymorphism
B)
Static polymorphism
C)
Executing polymorphism
D)
Non-executing polymorphism

Correct Answer : Option (A) :   Dynamic polymorphism


Explanation :

* In Run time Polymorphism: It is also known as Dynamic polymorphism as it is implemented during the run-time of the program.
* It is also known as Dynamic binding, Late binding and overriding as well.
* Run time polymorphism is more flexible as all things execute at run time.

A)
std is a standard class in C++
B)
std is a standard header file in C++
C)
std is a standard namespace in C++
D)
std is a standard file reading header in C++

Correct Answer : Option (C) :   std is a standard namespace in C++


Explanation : std is a standard namespace present in C++ which contains different stream classes and objects like cin, cout, etc. and other standard functions.

A)
input
B)
print
C)
cin
D)
cout

Correct Answer : Option (C) :   cin


Explanation : C++ uses cin to read input form uses. However C++ also uses scanf().

A)
The process of linking the actual code with a procedural call during run-time
B)
The process of linking the actual code with a procedural call during compile-time
C)
The process of linking the actual code with a procedural call at any-time
D)
All of the above

Correct Answer : Option (B) :   The process of linking the actual code with a procedural call during compile-time


Explanation : By default, C++ matches a function call with the correct function definition at compile-time. This is called static binding. You can specify that the compiler match a function call with the correct function definition at runtime; this is called dynamic binding.

A)
The process of linking the actual code with a procedural call during run-time
B)
The process of linking the actual code with a procedural call during compile-time
C)
The process of linking the actual code with a procedural call at any-time
D)
All of the above

Correct Answer : Option (A) :   The process of linking the actual code with a procedural call during run-time


Explanation : C++ provides facility to specify that the compiler should match function calls with the correct definition at the run-time; this is called dynamic binding or late binding or run-time binding. Dynamic binding is achieved using virtual functions. Base class pointer points to derived class object.

A)
No error in both C and C++
B)
Error in both C and C++
C)
Error in C++ but not in C
D)
Error in C but not in C++

Correct Answer : Option (D) :   Error in C but not in C++


Explanation : The above definition will give an error in C but not in C++ as C does not allows the programmer to give any default values to any member of structure but C++ does allow.

A)
2
B)
4
C)
2 or 4
D)
Based on the number of bits in the system

Correct Answer : Option (D) :   Based on the number of bits in the system


Explanation : Compiler wants to make CPU as more efficient in accessing the next value.

A)
Yes
B)
No, it is an enum of {false, true}
C)
No, it is expanded from macros
D)
No, it is a typedef of unsigned char

Correct Answer : Option (A) :   Yes


Explanation : C++ has bool as a fundamental data type.

A)
64
B)
128
C)
256
D)
512

Correct Answer : Option (B) :   128


Explanation : There are 128 characters defined in the C++ ASCII list.

A)
Unsigned integer of at least 64 bits
B)
Signed integer of at least 64 bits
C)
Unsigned integer of at least 16 bits
D)
Signed integer of at least 16 bits

Correct Answer : Option (C) :   Unsigned integer of at least 16 bits


Explanation : The size_t type is used to represent the size of an object. Hence, it’s always unsigned. According to the language specification, it is at least 16 bits.

A)
long double
B)
short float
C)
float
D)
double

Correct Answer : Option (B) :   short float


Explanation : Floating point types occur in only three sizes-float, long double and double.

A)
sizeof
B)
malloc
C)
calloc
D)
None of the above

Correct Answer : Option (A) :   sizeof


Explanation : The sizeof operator gives the size of the object or type.

A)
float
B)
string
C)
string & float
D)
integer

Correct Answer : Option (D) :   integer


Explanation : In C++, enumerations are stored as integers by the compiler starting with 0.

67 .
What does the following statement mean?
int (*fp)(char*)​
A)
pointer to a pointer
B)
pointer to an array of chars
C)
function taking a char* argument and returning a pointer to int
D)
pointer to function taking a char* argument and returns an int

Correct Answer : Option (C) :   pointer to function taking a char* argument and returns an int

A)
array[7];
B)
array[6];
C)
array(7);
D)
array(6);

Correct Answer : Option (B) :   array[6];


Explanation : The array location starts from zero, So it can accessed by array[6].

A)
0
B)
2
C)
4
D)
8

Correct Answer : Option (C) :   4


Explanation : Size of any type of pointer is 4 bytes in 32-bit platforms.

70 .
What will be the output of the following C++ code?

 #include 
   using namespace std;
   int main()
   {
       int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
       return 0;
   }​
A)
21 21 21
B)
15 18 21
C)
24 24 24
D)
Compile time error

Correct Answer : Option (A) :   21 21 21


Explaination :

a[1][2] means 1 * (4)+2 = 6th element of an array starting from zero.

Output :
$ g++ point.cpp
$ a.out
21 21 21​

A)
integer numerals
B)
floating-point numerals
C)
strings and boolean values
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : Because these are the types used to declare variables and so these can be declared as constants.

A)
we can not create the array of reference
B)
we can use variable
C)
we can use reference to reference
D)
we can create the Array of reference

Correct Answer : Option (A) :   we can not create the array of reference


Explanation :

It is not allowed in C++ to make an array of references. To test check following array :

int &arr[] = {&a, &b, &c};

This will give an error.

73 .
What will be the output of the following C++ code?
#include <iostream>
 using namespace std;
 void print (char * a)
 {
     cout << a << endl;
 }
 int main ()
 {
     const char * a = "Hello world";
     print(const_cast<char *> (a) );
     return 0;
 } ​
A)
compile time error
B)
Hello world
C)
Hello
D)
World

Correct Answer : Option (B) :   Hello world


Explaination :

In this program we used the concept of constant casting to cast the variable and printing it.

Output :
$ g++ ref2.cpp
$ a.out
Hello world

74 .
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
	int a = 5;
	int *p = &a;
	int &q = a;
	cout<<p<<endl;
	cout<<q<<endl;
	return 0;
}​
A)
Address of a followed by 5 in next line
B)
Address of p followed by 5 in next line
C)
Address of a followed by Address of a in next line
D)
Address of p followed by Address of q in next line

Correct Answer : Option (A) :   Address of a followed by 5 in next line


Explaination : Pointer p stores the address of variable whereas q is alias for variable a therefore when p is printed it prints the address of a and when q is printed value of a is printed.

A)
A reference once established cannot be changed
B)
A reference cannot be null
C)
The reference doesn’t need an explicit dereferencing mechanism
D)
All of the above

Correct Answer : Option (C) :   The reference doesn’t need an explicit dereferencing mechanism


Explanation : References can never be NULL. It is not allowed to change a reference once allocated. Referencing does not need an explicit referencing operator.

A)
int
B)
float
C)
double
D)
all of the above

Correct Answer : Option (D) :   all of the above


Explanation : Because it doesn’t know the type of object it is pointing to, So it can point to all objects.

A)
using shift keyword
B)
when it cast to another type of object
C)
when it doesn’t point to any value
D)
using delete keyword

Correct Answer : Option (B) :   when it cast to another type of object


Explanation : By casting the pointer to another data type, it can be dereferenced from the void pointer.

A)
static
B)
const
C)
volatile
D)
both const & volatile

Correct Answer : Option (D) :   both const & volatile


Explanation : Pointer can point to any variable that is not declared with const & volatile.

A)
members
B)
objects
C)
data
D)
objects & data

Correct Answer : Option (A) :   members


Explanation : Variables declared inside a class are called as data elements or data members.

A)
isdigit()
B)
isblank()
C)
isalpha()
D)
isalnum()

Correct Answer : Option (C) :   isalpha()


Explanation : Character classification provides isalpha() function to check whether a character in C++ is an alphabet or not.

A)
namespace,operator
B)
namespace#operator
C)
namespace::operator
D)
namespace$operator

Correct Answer : Option (C) :   namespace::operator


Explanation :

To access variables from namespace we use following syntax :

namespace :: variable;

General syntax :

namespace X{ int a;}
cout<<X::a;

A)
static
B)
const
C)
using
D)
dynamic

Correct Answer : Option (C) :   using


Explanation :

using keyword is used to specify the name of the namespace to which the variable belongs.

EX : 
namespace A{ int a = 5;}
namespace B{ int a = 10;}
using namespace A;
cout<<a; // will print value of a from namespace A.
using namespace B;
cout<<a; // will print value of a from namespace B.

A)
overloaded
B)
extensible
C)
reprehensible
D)
encapsulated

Correct Answer : Option (B) :   extensible


Explanation : Extensible is used to add new features to C++.

A)
the statement is ignored
B)
bool value evaluates to true
C)
an error is flagged
D)
bool value evaluates to false

Correct Answer : Option (D) :   bool value evaluates to false


Explanation : A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zero valued pointer converts to false.

A)
++
B)
--
C)
++ & --
D)
None of the above

Correct Answer : Option (A) :   ++


Explanation : Due to the history of using integer values as booleans, if an integer is used as a boolean, then incrementing will mean that whatever its truth value before the operation, it will have a truth-value of true after it. However, it is not possible to predict the result of -- given knowledge only of the truth value of x, as it could result in false.

86 .
What is the value of p in the following C++ code?
#include <iostream>
using namespace std;
int main()
{
        int p;
        bool a = true;
        bool b = false;
        int x = 10;
        int y = 5;
        p = ((x | y) + (a + b));
        cout << p;
        return 0;
}​
A)
B)
2
C)
12
D)
16

Correct Answer : Option (D) :   16


Explaination : | means bitwise OR operation so x | y (0101 | 1010) will be evaluated to 1111 which is integer 15 and as a is true and b is false so a+b(1 + 0) = 1. So final value of expression in line #10 will be 15 + 1 = 16.

A)
Implementation dependent
B)
Unsigned Implementation
C)
Signed
D)
Unsigned

Correct Answer : Option (A) :   Implementation dependent


Explanation : The standard does not specify if plain char is signed or unsigned. There are three distinct character types according to the standard: char, signed char and unsigned char.

A)
Implementation defined
B)
No, they are not different
C)
Yes, they are different
D)
Can’t say

Correct Answer : Option (C) :   Yes, they are different


Explanation : In C++, sizeof(‘a’) == sizeof(char) == 1. In C however, sizeof(‘a’) == sizeof(int).

A)
BIT_CHAR
B)
CHAR_BIT
C)
SIZE_CHAR
D)
CHAR_SIZE

Correct Answer : Option (B) :   CHAR_BIT


Explanation : CHAR_BIT is a macro constant defined in <climits> header file which expresses the number of bits in a character object in bytes.

A)
(~v & (v – 1)) == 0;
B)
(v | (v – 1)) == 0;
C)
(v | (v + 1)) == 0;
D)
(v & (v – 1)) == 0;

Correct Answer : Option (D) :   (v & (v – 1)) == 0;


Explanation : Power of two integers have a single set bit followed by unset bits.

A)
x = x | (x-1)
B)
x = x & (x-1)
C)
x = x | (x+1)
D)
x = x & (x+2)

Correct Answer : Option (B) :   x = x & (x-1)


Explanation : If x is odd the last bit will be 1 and last bit of x-1 will become 0. If x is even then last bit of x will be 0 and last bit of x-1 will become 1. In both case AND operation of 1 and 0 will be 0. Hence last bit of final x will be 0.

92 .
What will be the output of the following C++ function?
int main()
    {
        register int i = 1;
        int *ptr = &i;
        cout << *ptr;
	return 0;
    }​
A)
B)
1
C)
Runtime error may be possible
D)
Compiler error may be possible

Correct Answer : Option (D) :   Compiler error may be possible


Explaination : Using & on a register variable may be invalid, since the compiler may store the variable in a register, and finding the address of it is illegal.

A)
long double
B)
extended float
C)
float
D)
double

Correct Answer : Option (A) :   long double


Explanation : Float for single precision, double for double precision and long double for extended precision.

A)
-3.4E+38 to +3.4E+34
B)
-3.4E+38 to +3.4E+36
C)
-3.4E+38 to +3.4E+38
D)
None of the above

Correct Answer : Option (C) :   -3.4E+38 to +3.4E+38


Explanation : This is the defined range of floating type number sin C++. Also range for +ve and -ve side should be same so the answer is -3.4E+38 to +3.4E+38.

A)
it will not allocate memory
B)
allocate memory to objects
C)
it will allocate memory
D)
it will not allocate memory to its variables

Correct Answer : Option (A) :   it will not allocate memory


Explanation : Enumerator will allocate the memory when its variables are defined.

A)
float variable
B)
string variable
C)
float & string variable
D)
int variable

Correct Answer : Option (D) :   int variable


Explanation : The enum variable is converted to an integer and stored by the compiler. So both are equal in size.

97 .
What will happen in the following C++ code snippet?
int a = 100, b = 200;
int *p = &a, *q = &b;
p = q;​
A)
a is assigned to b
B)
p now points to b
C)
q now points to a
D)
b is assigned to a

Correct Answer : Option (B) :   p now points to b


Explaination : Assigning to reference changes the object to which the reference is bound.

A)
l prefix
B)
L prefix
C)
W prefix
D)
Z prefix

Correct Answer : Option (B) :   L prefix


Explanation : It can turn this as the wide character instead of narrow characters.

A)
&
B)
*
C)
->
D)
^

Correct Answer : Option (A) :   &


Explanation : & operator is used for assigning references.

A)
it will be declared
B)
it will allocate the memory
C)
it will not allocate any memory
D)
it will be declared and initialized

Correct Answer : Option (C) :   it will not allocate any memory


Explanation : While the structure is declared, it will not be initialized, So it will not allocate any memory.

A)
structure creator
B)
structure signifier
C)
structure creator & signifier
D)
structure specifier

Correct Answer : Option (D) :   structure specifier


Explanation : The structure declaration with open and close braces and with a semicolon is also called structure specifier.

A)
isblank()
B)
isalpha()
C)
isdigit()
D)
isalnum()

Correct Answer : Option (C) :   isdigit()


Explanation : Character classification provides isdigit() function to check whether a character in C++ is number or not.

103 .
What will be the output of the following C++ code?
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char const *argv[])
{
	char arr[12] = "H3ll0\tW0r1d";
	for(int i=0;i<12;i++)
        {
		cout<<(bool)isprint(arr[i]);
	}
}​
A)
111110000000
B)
111110111110
C)
111000111110
D)
111111111110

Correct Answer : Option (B) :   111110111110


Explaination : In this program we are checking the presence of alphabets and digits in the string so accordingly one can find the answer.

A)
delete ptr[];
B)
delete[] ptr;
C)
[]delete ptr;
D)
delete ptr;

Correct Answer : Option (B) :   delete[] ptr;

A)
T operator++(int);
B)
T& operator++(int);
C)
T operator++();
D)
T& operator++();

Correct Answer : Option (A) :   T operator++(int);


Explanation : The parameter int is just to signify that it is the postfix form overloaded. Shouldn’t return reference as per its original behavior.

106 .
Which of the following is the correct syntax to add the header file in the C++ program?
 
#include<userdefined.h>
A)
#include<userdefined>
B)
#include "userdefined.h"
C)
<include> "userdefined.h"
D)
Both A and B

Correct Answer : Option (D) :   Both A and B


Explaination :

To include the herder files in the C++ program user can use any of the following given syntax.
 
#include <Filename.h>  
Or
#include "filename.h"  

A)
cout <<"Hello world!";
B)
Cout << Hello world! ;
C)
Out <<"Hello world!;
D)
None of the above

Correct Answer : Option (A) :   cout <<"Hello world!";


Explanation : To print the message in the C++ language user can use the following syntax :

#include <iostream>  
using namespace std;  
  
int main() {  
  cout << "Hello World!";  
  cout << "I am learning C++";  
  return 0;  
}  ​

A)
Encapsulation
B)
Polymorphism
C)
Inheritance
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : There is nothing that forces a user to use the OOP concept in C++. In contrast, it is necessary for a programming language that it must support all three features as encapsulation, inheritance, and polymorphism completely to become a pure Object-Oriented Language.

A)
Function call
B)
Type cast
C)
Array subscripting
D)
Addition and subtraction

Correct Answer : Option (B) :   Type cast


Explanation : There are many rights to left associativity operators in C++, which means they are evaluation is done from right to left. Type Cast is one of them. Here is a link of the associativity of operators: https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/cpp/cpp-built-in-operators-precedence-and-associativity.md

A)
equality
B)
shift
C)
postfix
D)
unary

Correct Answer : Option (C) :   postfix


Explanation : The operator which is having the highest precedence is postfix and lowest is equality.

A)
it converts the virtual base object to derived class
B)
it will convert the operator based on precedence
C)
it converts virtual base class to derived class
D)
it converts the virtual base object to derived objects

Correct Answer : Option (C) :   it converts virtual base class to derived class


Explanation : Because the dynamic_cast operator is used to convert from base class to derived class.

A)
2
B)
3
C)
4
D)
5

Correct Answer : Option (D) :   5


Explanation : There are five sequences of statements. They are Preprocessor directives, Comments, Declarations, Function Declarations, Executable statements.

A)
Conditional operator
B)
Bitwise operator
C)
Addition operator
D)
Multiplicative operator

Correct Answer : Option (A) :   Conditional operator


Explanation : In the conditional operator, it will predicate the output using the given condition.

A)
certain structure
B)
selective structure
C)
bitwise structure
D)
choosing structure

Correct Answer : Option (B) :   selective structure


Explanation : The switch statement is used to choose the certain code to execute, So it is also called as selective structure.

115 .
What will be the output of the following C++ code?
#include <iostream>
    using namespace std;
    int main()
    {
        int i;
        for (i = 0; i < 10; i++);
        {
            cout << i;
        }
        return 0;
    }
A)
10
B)
0123456789
C)
012345678910
D)
compile time error

Correct Answer : Option (A) :   10


Explaination :

for loop with a semicolon is called as body less for loop. It is used only for incrementing the variable values. So in this program the value is incremented and printed as 10.
Output :
$ g++ stat2.cpp
$ a.out
10

A)
while
B)
do-while
C)
for
D)
all looping processes require that the iterations be known

Correct Answer : Option (C) :   for


Explanation : Because in for loop we are allowed to provide starting and ending conditions of loops, hence fixing the number of iterations of loops, whereas no such things are provided by other loops.

A)
Pure Object oriented
B)
Semi Object-oriented or Partial Object-oriented
C)
Not Object oriented
D)
None of the above

Correct Answer : Option (B) :   Semi Object-oriented or Partial Object-oriented


Explanation :

The common thing about the Pure Object-oriented language it provides three basic features like Inheritance, Encapsulation, and Polymorphism. Each programming language that supports these entire three features is known as the Pure-Object oriented language. Whereas if a programming language support all these three features but not support completely are known as the Partial-Object oriented languages or the Semi Object-oriented languages
 
The main reasons why the C++ programming language is Known as Semi-Object oriented language are as follows:
 
i) Availability of the Friend function : 
A friend class is allowed to access private and protected members of another class, within which it is declared a friend. It may be very useful for some time, but still, it violates the rule of the Object-Oriented features.

ii) Concept of the Global variable :
As we all know that we can declare a global variable in C++ language that can be easily accessible from anywhere within the program. So again, C++ does not provide complete privacy because no one is restricted to access and manipulate that data/information. Hence it offers partial Encapsulation, unlike Java Language, in which a user only allows to declare a variable within the class and can provide access specifier to it.

iii) The main function is Out-side the class :
C++ is an object-oriented language, but still, object-oriented is not fundamentally related (or implicit) to the language. So a user can easily write a valid, well-defined C++ code even without using any object once.

A)
High-level Language
B)
Low-level language
C)
Middle-level language
D)
None of the above

Correct Answer : Option (C) :   Middle-level language


Explanation : C++ contains the features of both types of high and Low-level programming languages, and it is also not wrong if we call it the combination of both high and low-level languages.

A)
comments are parts of the source code disregarded by the compiler
B)
comments are executed by the compiler
C)
comments are executable
D)
comments are executed by the compiler to find the meaning of the comment

Correct Answer : Option (A) :   comments are parts of the source code disregarded by the compiler


Explanation : Comments are used to add meaning to the program.

A)
void function
B)
else function
C)
user-defined function
D)
main function

Correct Answer : Option (D) :   main function


Explanation : Normally the execution of the program in c++ starts from main only.

A)
r distinguishes between comments and inner data
B)
r distinguishes between comments and outer data
C)
distinguishes between comments and outer data
D)
distinguishes between comments and code

Correct Answer : Option (D) :   distinguishes between comments and code


Explanation : To distinguish between different parts of the program like comments, codes, etc.

A)
It will return value
B)
It will not return value to its caller
C)
It will return value to its caller
D)
May or may not depend on the declared return type of the function, the passed arguments are different than the function return type

Correct Answer : Option (B) :   It will not return value to its caller


Explanation : As void is not having any return value, it will not return the value to the caller.

A)
parameters, function name
B)
parameters, variables
C)
return type, function name
D)
return type, function name, parameters

Correct Answer : Option (C) :   return type, function name


Explanation : In a function, return type and function name are mandatory all else are just used as a choice.

A)
127
B)
102
C)
99
D)
90

Correct Answer : Option (A) :   127


Explanation : C99 allows to pass a maximum of 127 arguments in a function.

A)
call by reference
B)
call by pointer
C)
call by object
D)
call by value

Correct Answer : Option (A) :   call by reference


Explanation : In the call by reference, it will just passes the reference of the memory addresses of passed values rather than copying the value to new memories which reduces the overall time and memory use.

A)
whole program
B)
the main function
C)
header section
D)
only inside the {} block

Correct Answer : Option (D) :   only inside the {} block


Explanation : The variable is valid only in the function block as in other.

A)
It becomes a virtual function of the class
B)
It becomes an inline function of the class
C)
It becomes a default calling function of the class
D)
The program gives an error

Correct Answer : Option (B) :   It becomes an inline function of the class


Explanation : Any function which is defined inside a class and has no complex operations like loops, a large number of lines then it is made inline.

A)
A function that is called during compile time
B)
A function that is not checked for semantic analysis
C)
A function that is expanded at each call during execution
D)
A function that is not checked for syntax errors

Correct Answer : Option (C) :   A function that is expanded at each call during execution


Explanation : Inline function is those which are expanded at each call during the execution of the program to reduce the cost of jumping during execution.

A)
Middle of the parameter list
B)
Anywhere inside the parameter list
C)
To the rightmost side of the parameter list
D)
To the leftmost side of the parameter list

Correct Answer : Option (C) :   To the rightmost side of the parameter list


Explanation : Default parameters are defined to the rightmost side of parameter list in a function to differentiate between the normal and default parameters for example if a function is defined as fun(int x = 5, int y) then if we call fun(10) then 10 should be given to x or y because one can apply both logics like x = 10 already defined and 10 passed is for y but if compiler reads it from left to right it will think it is for x and no parameter is given for y, therefore, the compiler will give error.

130 .
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
 
int fun(int=0, int = 0);
 
int main()
{
  cout << fun(5);
  return 0;
}
int fun(int x, int y) { return (x+y); }
A)
5
B)
10
C)
-5
D)
-10

Correct Answer : Option (A) :   5


Explaination : C++ allows to define such prototype of the function in which you are not required to give variable names only the default values. While in function definition you can provide the variable names corresponding to each parameter.

A)
start() function
B)
end() function
C)
new() function
D)
main() function

Correct Answer : Option (D) :   main() function


Explanation : The execution of a C++ program starts from the main() function.

132 .
What is the output of the given program?
#include < stdio.h >  
using namespace std;  
int main()  
{  
int array[] = {10, 20, 30};  
cout << -2[array];  
return 0;  
}
A)
-15
B)
-30
C)
Garbage value
D)
Compiler error

Correct Answer : Option (B) :   -30


Explaination : It will print the negative value of the specified values because the "-" sign we used while specifying the array elements. So the correct answer will be the "-30".

A)
In the C++ programming language, there are two types of arrays
B)
In the C++ programming language, there are three types of arrays
C)
In the C++ programming language, there are four types of arrays
D)
In the C++ programming language, there are five types of arrays

Correct Answer : Option (A) :   In the C++ programming language, there are two types of arrays


Explanation : In the C++ programming language, there are mainly two types of arrays that are Single Dimension arrays and Multi-Dimension arrays. In Single-Dimension arrays, the same types of values are hold in the form of a List, while on the other hand, in Multi-Dimension arrays; values are stored in the form of a matrix.

A)
It returns the maximum number of elements that can be stored in the array
B)
It returns the dimension of the specified array
C)
It returns the size of each dimension
D)
None of the above

Correct Answer : Option (B) :   It returns the dimension of the specified array


Explanation : In C++, one can use the rank function where he wants to know about the dimensions( e.g., single-dimension, multi-dimension) of a specific array by just passing it to the "rank()" function.

135 .
Read the given C++ program carefully and choose the correct output from the given options:
#include <iostream>  
#include <string>  
using namespace std;  
int main()  
{  
    cout<<rank<int[10]>::value; // Case A  
    cout<<rank<char[10][10]>::value;   // Case B  
    cout<<rank<string[10][10][10]>::value; //Case C  
    return 0;  
} 
A)
010
B)
121
C)
123
D)
321

Correct Answer : Option (C) :   123


Explaination : As we can see in the above program, here, the "rank()" function is used. The "rank()" function is used to know about the dimensions of the passed array. In case A the array passed to the "rank()" function is single-dimensional, In case B, the passed array is 2-dimensional, and in case C, the array passed is three-dimensional. So the output return by the "rank()" function is 123.

A)
const
B)
static
C)
virtual
D)
absolute

Correct Answer : Option (A) :   const


Explanation : Because const will not change the value of the variables during the execution.

A)
call by reference
B)
call by pointer
C)
call by object
D)
call by value

Correct Answer : Option (D) :   call by value


Explanation : call by value

A)
same function
B)
main function
C)
caller function
D)
block function

Correct Answer : Option (C) :   caller function


Explanation : The execution of the program is returned to the point from where the function was called and the function from which this function was called is known as caller function.

A)
different function name but different number of arguments
B)
same function name but different number of arguments
C)
same function name but same number of arguments
D)
different function name but same number of arguments

Correct Answer : Option (B) :   same function name but different number of arguments


Explanation : Using the function overloading concept, we can develop more than one function with the same name, but the arguments passed should be of different types. Function overloading executes the program faster. Function overloading is used for code reusability and to save memory.

A)
type
B)
number of arguments
C)
type & number of arguments
D)
number of objects

Correct Answer : Option (C) :   type & number of arguments


Explanation :

Both type and number of arguments permits function overloading in C++, like
int func(int);
float func(float, float)
Here both type and number of arguments are different.

A)
constructor overloading
B)
destructor overloading
C)
function overloading
D)
operator overloading

Correct Answer : Option (A) :   constructor overloading


Explanation : In constructor overloading, we will be using the same options availed in function overloading.

A)
The function declaration should contain $
B)
The function declaration should contain ampersand (& in its type declaration)
C)
The values of those variables are passed to the function so that it can manipulate them
D)
The location of variable in memory is passed to the function so that it can use the same memory area for its processing

Correct Answer : Option (D) :   The location of variable in memory is passed to the function so that it can use the same memory area for its processing


Explanation : In pass by reference, we can use the function to access the variable and it can modify it. Therefore we are using pass by reference.

A)
There is need to copy parameter values (i.e. less memory used)
B)
There is no need to call constructors for parameters (i.e. faster)
C)
Changes to parameter values within the function also affect the original arguments
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : All the above mentioned are advantages and properties of call by reference.

A)
Delete is syntactically correct although, if the Delete[] is used, it will obtain an error.
B)
The "Delete" is used for deleting a single standard object, whereas the "Delete[]" is used for deleting an array of the multiple objects
C)
The "Delete" is a type of keyword, whereas the "Delete[]" is a type of identifier
D)
The "Delete" is used for deleting the standard objects, while on the other hand, the "Delete[]" is used to delete the pointer objects

Correct Answer : Option (B) :   The "Delete" is used for deleting a single standard object, whereas the "Delete[ ]" is used for deleting an array of the multiple objects


Explanation : The "Delete" is used with the single general object, while on the other hand, the "Delete[ ]" is used with the array of the multiple objects initiated with the new operator.

A)
By declaring a virtual function in the base class
B)
By using the pure virtual function in the class
C)
By declaring the virtual keyword afterward, the class Declaration
D)
None of the above

Correct Answer : Option (B) :   By using the pure virtual function in the class


Explanation : A class must contain at least one declaration of the pure virtual function in itself to be called an abstract class. Therefore to make an abstract class, one has to declare at least one pure virtual function in that class.

A)
vg_list
B)
arg_list
C)
va_list
D)
both va_list & arg_list

Correct Answer : Option (C) :   va_list


Explanation : va_list is provided by C++ to access manipulated arguments in function.

A)
va_start
B)
va_list
C)
va_arg
D)
vg_arg

Correct Answer : Option (A) :   va_start


Explanation : va_start initialises the the list of arguments in <stdarg.h> header file.

A)
It is not even allowed in C++
B)
It will not have the Constructor
C)
Both (A) and (B)
D)
It will not have the destructor

Correct Answer : Option (D) :   It will not have the destructor


Explanation : In the C++ program, if we use a class without assigning a name. As a result, it will not be going to have a destructor, but it will have the object. To understand it in more detail, consider the following program:

#include 
using namespace std;
class
{
    public:
	void func()
        {
		cout<<"Hello world";
	}
}a;
int main(int argc, char const *argv[])
{
	a.func();
	return 0;
}​

A)
Bottom-up
B)
Top to bottom
C)
Right to left
D)
Left to right

Correct Answer : Option (A) :   Bottom-up


Explanation : Generally, C++ uses the Bottom-up approach while other programming languages like C use the top-down approach.

A)
By using the Template
B)
By using only the virtual functions
C)
By using the concepts of inheritance
D)
By using both the virtual functions and inheritance

Correct Answer : Option (D) :   By using both the virtual functions and inheritance


Explanation : In C++, one can implement the run-time Polymorphism by using the virtual functions and inheritance where the object decides which function to call.

A)
X,Y->Z
B)
X->Y->Z
C)
X->Y;X->Z
D)
None of the above

Correct Answer : Option (A) :   X,Y->Z


Explanation : In multiple inheritances, a single class can inherit properties form more than one base class.

A)
ASM
B)
asm
C)
Compiler specific
D)
Not possible

Correct Answer : Option (B) :   asm


Explanation :

In the C ++ programming language, one can use the "asm" keyword to write assembly code as an inline function. To understand this in more detail, please consider the following example:
 
Sample demo of "asm" keyword use:
#include<bits/stdc++.h>  
usingnamespacestd;  
intmain()  
{  
  // generates interrupt 5  
  asmint5;    
    
  return0;  
}

A)
Don't alter anything
B)
Increases the amount of code
C)
Reduces the amount of code in the cache
D)
Increases the amount of code in the cache

Correct Answer : Option (C) :   Reduces the amount of code in the cache


Explanation : Compilers may try to move the catch-code far away from the try-code, which reduces the amount of code to keep in the cache, thus it will enhance the overall performance.

154 .
What is the meaning of the following declaration?

int(*ptr[5])();
A)
ptr is pointer to function
B)
ptr is pointer to array of function
C)
ptr is array of pointer to function
D)
ptr is pointer to such function which return type is array

Correct Answer : Option (C) :   ptr is array of pointer to function


Explaination : In this expression, ptr is array not pointer.

A)
macro
B)
define
C)
#macro
D)
#define

Correct Answer : Option (D) :   #define


Explanation : #define is the keyword which is used to define the macros in c++.

A)
#include <iostream>
B)
#define <iostream>
C)
#undef <iostream>
D)
#macro <iostream>

Correct Answer : Option (A) :   #include <iostream>


Explanation : For a c++ program to execute, we need #include<iostream>.

A)
link directive
B)
scripted directive
C)
executed directive
D)
executed & link directive

Correct Answer : Option (B) :   scripted directive


Explanation : When the compiler encounters a previously defined macro, it will take the result from that execution itself.

158 .
What will be the output of the following C++ code?
 #include <iostream>
    using namespace std;
    #define PR(id) cout << "The value of " #id " is "<<id
    int main()
    {
        int i = 10;
        PR(i);
        return 0;
    }
A)
10
B)
15
C)
20
D)
25

Correct Answer : Option (A) :   10


Explaination :

In this program, we are just printing the declared values.
Output :
$ g++ mac.cpp
$ a.out
10

A)
constant variables
B)
absolute variables
C)
abstract classes
D)
default variables

Correct Answer : Option (C) :   abstract classes


Explanation : Abstract classes in C++ are purposely defined for making base classes containing atleast one virtual function which can be overloaded on inheritance, which means single function name for different sub-classes, hence acts as an interface.

A)
methods & instance of a class
B)
instance of a class
C)
methods
D)
pure abstract class

Correct Answer : Option (D) :   pure abstract class


Explanation : Pure abstract classes in C++ are a type of interface because it contains only abstract member functions and no data or concrete member functions.

A)
scope operator
B)
bitwise operator
C)
conditional operator
D)
ternary operator

Correct Answer : Option (A) :   scope operator


Explanation :

Scope operator(::) is used in namespace syntax.
General syntax :
namespace X{ int a;}
cout<<X::a;

A)
try
B)
catch
C)
throw
D)
handlers

Correct Answer : Option (D) :   handlers


Explanation : When an exception is arisen mean, the exception is caught by handlers and then it decides the type of exception.

163 .
What is the return value of f(p, p) if the value of p is initialized to 5 before the call?
int f(int&x, int c) {  
c  = c - 1;  
if (c == 0) return 1;  
   x = x + 1;  
return f(x, c) * x;  
}  
Note that the first parameter is passed by reference, whereas the second parameter is passed by value.
A)
3024
B)
6561
C)
55440
D)
161051

Correct Answer : Option (B) :   6561


Explaination : In the given C++ program, we can clearly see that the c is passed by the value, but the x is passed by the reference. Therefore all functions in the given program will have the same copies of the x but different copies of the c.

A)
The function has several static variables
B)
Functions are large and contain several nested loops
C)
Usually, it is small, and we want to avoid the function calls
D)
All of the above

Correct Answer : Option (C) :   Usually, it is small, and we want to avoid the function calls


Explanation : In general, the inline functions are very small in size and more often used in the place of the macros as they are the substitute of the macros and many times better than the macros.

A)
Not possible
B)
By making the destructor private.
C)
By making the constructor private.
D)
By making both constructor and destructor private.

Correct Answer : Option (B) :   By making the destructor private.


Explanation :

One can make a c++ program in which a class's object can be created using only the " new "operator, and still, if the user wants and tries to create its object directly, the program will produce a compiler error. To can understand it more clearly, you can consider the following given example.
 
Example
 
// in this program, Objects of test can only be created using new
class Test1
{
private:
    ~Test1() {}
friend void destructTest1(Test1* );
};

// Only this function can destruct objects of Test1
voiddestructTest(Test1* ptr)
{
deleteptr;
}

int main()
{
    // create an object
    Test1 *ptr = new Test1;

    // destruct the object
    destructTest1 (ptr);

return 0;
}​

A)
Members
B)
Data
C)
Object & data
D)
None of the above

Correct Answer : Option (A) :   Members


Explanation : The data members declared within the structure are known as the members. 

A)
1
B)
2
C)
3
D)
4

Correct Answer : Option (C) :   3


Explanation : There are three types of linkage in c++. They are an internal linkage, external linkage, and no linkage.

A)
internal linkage
B)
external linkage
C)
no linkage
D)
internal & external linkage

Correct Answer : Option (D) :   external linkage


Explanation : In the external linkage, it is used to refer to identifiers in various programs.

A)
variable
B)
code
C)
declaration
D)
prototype

Correct Answer : Option (D) :   prototype


Explanation : By defining a function’s prototype in another file means, we can inherit all the features from the source function.

A)
cpp
B)
h
C)
hf
D)
hg

Correct Answer : Option (B) :   h


Explanation : .h extensions are used for user defined header files. To include a user defined header file one should use #include"name.h" i.e. enclosed within double quotes.

171 .
What will be the output of the following C++ code?
 
    #include <iostream>
    using namespace std;
    int main()
    {
        char name[30];
        cout << "Enter name: ";
        gets(name);
        cout << "Name: ";
        puts(name);
        return 0;
    }
A)
compile time error
B)
jobs
C)
jobsjobs
D)
program will not run

Correct Answer : Option (A) :   compile time error


Explaination : This program will run on older version of C++ with the inclusion of #include header file, but for on new compiler C++14 and above the gets is removed from the header file so it will not run on them even after inclusion of cstdio header file.

A)
<sstring>
B)
<sstream>
C)
<string>
D)
<iostream>

Correct Answer : Option (C) :   <string>


Explanation : stringstream is available under the header file <string> in C++.

A)
arrays
B)
data
C)
functions
D)
both data & functions

Correct Answer : Option (D) :   both data & functions


Explanation : The classes in C++ encapsulates(i.e. put together) all the data and functions related to them for manipulation.

A)
object A { int x; };
B)
class A { int x; };
C)
public class A { }
D)
class B { }

Correct Answer : Option (B) :   class A { int x; };


Explanation : A class declaration terminates with semicolon and starts with class keyword.

A)
private
B)
public
C)
protected
D)
public & protected

Correct Answer : Option (A) :   private


Explanation : By default all the data members and member functions of class are private.

A)
access is public by default
B)
access is denied
C)
access is private by default
D)
access is protected by default

Correct Answer : Option (A) :   access is public by default


Explanation : For structures, by default all the data members and member functions are public.

A)
Atomic data type
B)
Derived data type
C)
User defined derived data type
D)
Fundamental data type

Correct Answer : Option (C) :   User defined derived data type


Explanation : Fundamental/Atomic data type includes int, char, float, double and void. Derived data type includes arrays, pointers, references, function and constants. User defined derived data type includes class, structure, union and enumeration.

A)
By passing self as a parameter in the member function
B)
Using * with the name of that object
C)
Using a special keyword object
D)
Using this pointer

Correct Answer : Option (D) :   Using this pointer


Explanation : In Classes objects are self-referenced using this pointer inside the member functions. for example this->value to access the data member value of that object.

A)
A member that is global throughout the class
B)
A member that can be updated even if it a member of constant object
C)
A member that can never be changed
D)
A member that can be updated only if it not a member of constant object

Correct Answer : Option (B) :   A member that can be updated even if it a member of constant object


Explanation : Mutable members are those which can be updated even if it a member of a constant object. You can change their value even from a constant member function of that class.

180 .
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	int a = 5;
    public:
	void change(int i){
		a = i;
	}
	static void value_of_a(){
		cout<<a;
	}
};
 
int main(int argc, char const *argv[])
{
	A a1 = A();
	a1.change(10);
	a1.value_of_a();
	return 0;
}
A)
Segmentation Fault
B)
Error
C)
5
D)
10

Correct Answer : Option (B) :   Error


Explaination : As value_of_a() is a static function and static member can access only static members therefore the program will give error.

A)
It allow one same portion of memory to be accessed as different data types
B)
It allow one different portion of memory to be accessed as different data types
C)
It allow one different portion of memory to be accessed as same data types
D)
It allow one same portion of memory to be accessed as same data types

Correct Answer : Option (A) :   It allow one same portion of memory to be accessed as different data types


Explanation : Union is used to define the data types of our choice and it will store the data type in one location make them accessible.

A)
def NameByUser ExistingData
B)
def NameByUser ExistingDataType
C)
typedef ExistingDataType NameByUser
D)
typedef NameByUser ExistingDataType

Correct Answer : Option (C) :   typedef ExistingDataType NameByUser


Explanation :

correct syntax is typedef ExistingDataType NameByUser.
typedef int INT; (typedef existing-datatype New-name;).

A)
main function
B)
inside that block only
C)
outside the program
D)
whole program

Correct Answer : Option (D) :   whole program


Explanation : We are defining the user-defined data type to be availed only inside that program, if we want to use anywhere means we have to define those types in the header file.

A)
ternary operator
B)
resolution operator
C)
direct member access operator
D)
scope resolution operator

Correct Answer : Option (C) :   direct member access operator


Explanation : Objects in the method can be accessed using direct member access operator which is (.)

A)
member of the class
B)
instance of the class
C)
attribute of the class
D)
associate of the class

Correct Answer : Option (B) :   instance of the class


Explanation : An Object represents an instance of a class i.e. a variable of that class type having access to its data members and member functions from outside if allowed.

A)
The overloaded operator must have at least one operand of its class type
B)
The overloaded operators follow the syntax rules of the original operator
C)
Only existing operators can be overloaded
D)
None of the above

Correct Answer : Option (A) :   The overloaded operator must have at least one operand of its class type


Explanation : The overloaded operator must not have at least one operand of its class type.

187 .
What happens when objects s1 and s2 are added?
string s1 = "Hello";
string s2 = "World";
string s3 = (s1+s2).substr(5);
A)
Run-time error
B)
Segmentation fault as two string cannot be added in C++
C)
Error because s1+s2 will result into string and no string has substr() function
D)
The statements runs perfectly

Correct Answer : Option (D) :   The statements runs perfectly


Explaination : string is class in C++, therefore when we do (s1+s2) a temporary object is created which stores the result of s1+s2 and then that object calls the function substr() and as that is an object of string class hence substr is a callable function for that temporary string object.

A)
Redefining the way operator works for user defined types
B)
Ability to provide the operators with some special meaning for user defined data type
C)
Overriding the operator meaning by the user defined meaning for user defined data type
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type.

A)
A operator+(argument_list){ }
B)
A operator[+](argument_list){ }
C)
int [+](argument_list){ }
D)
int +(argument_list){ }

Correct Answer : Option (A) :   A operator+(argument_list){ }


Explanation :

The general syntax for operator overloading is :

return_type operator_keywordOperator(argument_list){ }

Ex : 
A opeartor+(argument_list){ }

A)
Operator that performs its action on three operand
B)
Operator that performs its action on a single operand
C)
Operator that performs its action on two operand
D)
Operator that performs its action on any number of operands

Correct Answer : Option (C) :   Operator that performs its action on two operand


Explanation : Binary operators are those operators that work with two operands. For example, a common binary expression would be a + b—the addition operator (+) surrounded by two operands. The binary operators are further subdivided into arithmetic, relational, logical, and assignment operators.

A)
Precedence of operators are changed after overlaoding
B)
Associativity and precedence of operators does not change
C)
Only arithmetic operators can be overloaded
D)
Only non-arithmetic operators can be overloaded

Correct Answer : Option (B) :   Associativity and precedence of operators does not change


Explanation : Both arithmetic and non-arithmetic operators can be overloaded. The precedence and associativity of operators remains the same after and before operator overloading.

A)
complex number
B)
complexnum
C)
complexarg
D)
complex

Correct Answer : Option (D) :   complex


Explanation : <complex> header file is used for declaring a complex number in C++.

193 .
What will be the output of the following C++ code?
    #include <iostream>
    #include <complex>
    using namespace std;
    int main ()
    {
        complex<double> mycomplex (20.0, 2.0);
        cout << imag(mycomplex) << endl;
        return 0;
    }
A)
2
B)
20
C)
30
D)
40

Correct Answer : Option (A) :   2


Explaination :

imag part will return the imaginary part of the complex number.

Outpu t:
$ g++ comp5.cpp
$ a.out
2

A)
it is used for storage
B)
result of the type conversion is a valid
C)
result of the type conversion is an invalid
D)
to be used in low memory

Correct Answer : Option (B) :   result of the type conversion is a valid


Explanation :  It is used to check that operators and operands are compatible after conversion.

A)
Stack
B)
Queue
C)
Stack & Queue
D)
memory heap

Correct Answer : Option (C) :   Memory heap


Explanation : Memory heap will store the large objects in c++ if it extends its allocated memory.

A)
delete the objects after processing
B)
rename the objects
C)
both rename & delete the objects
D)
add the objects

Correct Answer : Option (A) :   delete the objects after processing


Explanation : When you allocate memory from the heap, you must remember to clean up objects when you’re done! Failure to do so is called a memory leak.

A)
vector
B)
string
C)
class
D)
string & class

Correct Answer : Option (A) :   vector


Explanation : Because the vector is mainly used to store large objects for the game programming and other operations etc.

A)
pass by value
B)
pass by reference
C)
pass by name
D)
both pass by value & reference

Correct Answer : Option (B) :   pass by reference


Explanation : Because by using pass by reference we need to pass only address location, So it can save a lot of memory.

A)
setflimit()
B)
unlimit()
C)
setrlimit()
D)
both setrlimit() & unlimit()

Correct Answer : Option (C) :   setrlimit()


Explanation : setrlimit() is used to unlimit the size of the stack.

A)
top to bottom
B)
bottom to top
C)
left to right
D)
right to left

Correct Answer : Option (D) :   right to left


Explanation : In assignment operation, the flow of execution will be from right to left only.

A)
reference pointer
B)
dereference pointer
C)
memory locator
D)
store it in heap

Correct Answer : Option (B) :   dereference pointer


Explanation : If you have a pointer to an object of some class type that overloads the subscript operator, you have to dereference that pointer in order to free the memory.

A)
operator( )
B)
operator[ ]
C)
operator<>
D)
operator

Correct Answer : Option (A) :   operator( )


Explanation : The reason is that operator[] always takes exactly one parameter, but operator() can take any number of parameters.

A)
static member function
B)
non-static member function
C)
static_cast
D)
dynamis_cast

Correct Answer : Option (B) :   non-static member function


Explanation : In non-static member function, the function call operator can be overloaded.

A)
increment
B)
decrement
C)
both increment & decrement
D)
binary operator

Correct Answer : Option (C) :   both increment & decrement


Explanation : Because increment and decrement operator increases increasing and decreasing values of values and no such things define in strings so cannot be used with strings. Also they cannot be used with floats and doubles because there is no way to fix how much the value should be increased or decreased if increment or decrement operator is applied on such variables. That’s why both these operators only works with integer values.

205 .
What will be the output of the following C++ code?
    #include <stdio.h> 
    #include<iostream>
    using namespace std;
    int main()
    {
        int x = 5, y = 5;
        cout << ++x << --y << endl;
        return 0;
    }
A)
45
B)
46
C)
55
D)
64

Correct Answer : Option (D) :   64


Explaination :

The values will be pre increment and pre decrement, So it will print as 64.

Output :
$ g++ incre2.cpp
$ a.out
64

A)
data
B)
append
C)
operator+=
D)
both append & operator+=

Correct Answer : Option (D) :   both append & operator+=


Explanation : C++ allows to append more characters to string using both inbuilt append() function and using operator overloaded += operator.

A)
Stream of characters
B)
Stream of alphabets
C)
A stream of characters terminated by \0
D)
A stream of well-defined characters

Correct Answer : Option (D) :   A stream of well-defined characters


Explanation : Strings are objects that represent sequences of characters. The standard string class provides support for such objects with an interface similar to that of a standard container of bytes, but adding features specifically designed to operate with strings of single-byte characters.

A)
array of characters
B)
array of alphabets
C)
array of well-defined characters
D)
array of characters terminated by \0

Correct Answer : Option (A) :   array of characters


Explanation : In C programming, the collection of characters is stored in the form of arrays. This is also supported in C++ programming. Hence it's called C-strings. C-strings are arrays of type char terminated with null character, that is, \0 (ASCII value of null character is 0).

209 .
What will be the output of the following C++ code?
#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char str[10];
	cin>>str;
	cout<<str;
	return 0;
}
A)
Input given by the user
B)
Depends on the length of the string entered by the user
C)
Run-time Error
D)
Compiler-time Error

Correct Answer : Option (B) :   Depends on the length of the string entered by the user


Explaination :

As the character array size is 10 so if the string entered by the user is <= 10 then there will be no error and the program runs perfectly otherwise if the length is > 10 then the program gives a run-time error because the string crosses the allocated memory space.
Output :
length < 10

$ ./a.out 
Hello
Hello

length > 10
$ ./a.out 
C++Programming
*** stack smashing detected ***:  terminated
Aborted (core dumped)

A)
To destroy an object
B)
To modify the data whenever required
C)
To initialize the data members of an object when it is created
D)
To call private functions from the outer world

Correct Answer : Option (C) :   To initialize the data members of an object when it is created


Explanation : A constructor is used in classes to initialize data members of class in order to avoid errors/segmentation faults.

A)
Because user may forget to define init() function
B)
Because user may call init() more than once which leads to overwriting values
C)
Because user may forget to call init() using that object leading segmentation fault
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : We cannot use init() because as mentioned in options that user may forget to initialize the members which will lead to a segmentation fault. Also if the user calls the init() function more than once it may overwrite the values and may result into disastrous results. Also if any user forgets to define init() function then no object will be initialized whereas if any constructor is not defined in any class the class provides a default constructor for initialization.

A)
Error occurs
B)
Segmentation fault
C)
Compiler provides a default constructor to avoid faults/errors
D)
Objects are not created properly

Correct Answer : Option (C) :   Compiler provides a default constructor to avoid faults/errors


Explanation : The C++ compiler always provides a default constructor if one forgets to define a constructor inside a class.

A)
To destroy an object when the lifetime of an object ends
B)
To modify the data whenever required
C)
To call private functions from the outer world
D)
To initialize the data members of an object when it is created

Correct Answer : Option (A) :   To destroy an object when the lifetime of an object ends


Explanation : Destructors are used in Classes to destroy an object after its lifetime is over i.e. to free resources occupied by that object.

A)
When a program ends
B)
When a function ends
C)
When a delete operator is used
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation :

Destructors are called at the following time :

i) at the end of the program to destroy objects declared in the main() or global scope.
ii) at the end of a function to destroy objects declared at that function scope.
iii) when user by himself tries to delete an object using the delete operator.
iv) at the end of a block to destroy objects declared at that block scope.

A)
Assignment constructor
B)
Copy constructor
C)
Default constructor
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : If a programmer does not define the above constructors in a class the C++ compiler by default provides these constructors to avoid error on basic operations.

A)
When an object of the class is returned by value
B)
When an object of the class is passed by value to a function
C)
When an object is constructed based on another object of the same class
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : Copy constructor is called in all the above-mentioned criteria because in all the above cases we are somehow trying to copy one object into another.

A)
No chance for destructor overloading
B)
By changing the parameters type
C)
By changing the number of parameters
D)
By changing both the number of parameters and their type

Correct Answer : Option (A) :   No chance for destructor overloading


Explanation : A class is allowed to have only one destructor. Therefore there is no point of destructor overloading.

A)
A problem that arises during compilation
B)
A problem that arises during the execution of a program
C)
Also known as semantic error
D)
Also known as the syntax error

Correct Answer : Option (B) :   A problem that arises during the execution of a program


Explanation : An exception is defined as the problem in C++ program that arises during the execution of the program for example divide by zero error.

A)
To get correct output
B)
To successfully compile the program
C)
To avoid unexpected behaviour of a program during run-time
D)
To let compiler remove all exceptions by itself

Correct Answer : Option (C) :   To avoid unexpected behaviour of a program during run-time


Explanation : We need to handle exceptions in a program to avoid any unexpected behaviour during run-time because that behaviour may affect other parts of the program. Also, an exception is detected during run-time, therefore, a program may compile successfully even with some exceptions cases in your program.

A)
Using Error handling schedules
B)
Using Exception keyword
C)
Using try-catch block
D)
Using Exception block

Correct Answer : Option (C) :   Using try-catch block


Explanation : C++ provides a try-catch block to handle exceptions in your program.

A)
Both are the same
B)
Both can be handled during run-time
C)
Errors can be handled at the run-time but the exceptions cannot
D)
Exceptions can be handled at the run-time but the errors cannot

Correct Answer : Option (D) :   Exceptions can be handled at the run-time but the errors cannot


Explanation : Exceptions can be handled during run-time whereas errors cannot be because exceptions occur due to some unexpected conditions during run-time whereas about errors compiler is sure and tells about them during compile-time.

A)
An exception that is caught twice
B)
An exception that is not handled in one caught hence thrown again
C)
An exception that is thrown again as it is not handled by that catching block
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : Exception that is caught by a catch block but not handled by that catch block can be re-thrown by that catch block to further try-catch block.

A)
Set a global error indicator
B)
Use break keyword
C)
Use final keyword
D)
Use constructor and destructor

Correct Answer : Option (A) :   Set a global error indicator


Explanation : Set a global error indicator is most suitable for returning the logical errors in the program.

A)
Terminate the program
B)
Improve the exception safety
C)
Crash the compiler
D)
Exit from the block

Correct Answer : Option (B) :   Improve the exception safety


Explanation : RAII is used to improve the exception safety.

A)
After all the catch blocks
B)
After the catch block of Base class
C)
Before the catch block of Base class
D)
Anywhere in the sequence of catch blocks

Correct Answer : Option (C) :   Before the catch block of Base class


Explanation : C++ asks the programmer to place the catch block of derived class before a catch block of the base class, otherwise derived catch block will never be executed.

A)
catch(Exception e)
B)
catch(Exception ALL)
C)
catch(…)
D)
catch(ALL)

Correct Answer : Option (C) :   catch(…)


Explanation : catch(…) is used in C++ to catch all types of exceptions in a single catch block.

A)
execution of other functions of the program starts
B)
no effect on the program
C)
successful execution of programs
D)
termination of program

Correct Answer : Option (D) :   termination of program


Explanation : Uncaught exceptions in a program leads to the termination of a program.

A)
Static errors
B)
Memory allocation errors
C)
I/O errors
D)
Both Memory allocation errors & I/O errors

Correct Answer : Option (D) :   Both Memory allocation errors & I/O errors


Explanation : Both Memory allocation errors & I/O errors are the predefined exceptions in c++.

A)
Deriving new classes from existing classes
B)
Classes with same names
C)
Overloading of classes
D)
Wrapping of data into a single class

Correct Answer : Option (A) :   Deriving new classes from existing classes


Explanation :

In C++, inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class.
 
In C++, the class which inherits the members of another class is called derived class and the class whose members are inherited is called base class. The derived class is the specialized class for the base class.

A)
Any member function of a class
B)
All functions that are derived from the base class
C)
All the members that are accessing base class data members
D)
All the functions which are declared in the base class and is re-defined/overridden by the derived class

Correct Answer : Option (D) :   All the functions which are declared in the base class and is re-defined/overridden by the derived class


Explanation : Virtual function is a function that is declared inside the base class and is re-defined inside the derived class.

A)
They are used to achieve runtime polymorphism
B)
They are used to hide objects
C)
Each virtual function declaration starts with the virtual keyword
D)
All of the above

Correct Answer : Option (B) :   They are used to hide objects


Explanation : Virtual function are used to achieve runtime polymorphism by calling the right function during runtime. Their declaration starts with a virtual keyword.

A)
Any function that is made virtual
B)
A virtual function defined inside the base class
C)
A virtual function that has no definition relative to the base class
D)
A virtual function that is defined inside the derived class

Correct Answer : Option (C) :   A virtual function that has no definition relative to the base class


Explanation : A virtual function that has no definition relative to the base class is called a pure virtual function.

A)
Constructor of A only
B)
Constructor of B only
C)
Constructor of A followed by B
D)
Constructor of B followed by A

Correct Answer : Option (C) :   Constructor of A followed by B


Explanation : Firstly the Constructor of class A is called then class B because the Constructor of the base class is called before derived class.

A)
late binding
B)
static binding
C)
compile time binding
D)
no binding

Correct Answer : Option (A) :   late binding


Explanation : Virtual function in C++ adds the power of late binding by deciding the type of object during run-time.

A)
The variable is visible everywhere
B)
The variable is not visible to its block
C)
The variable is visible only outside inside the block
D)
The variable is visible to its block and to it’s derived class

Correct Answer : Option (D) :   The variable is visible to its block and to it’s derived class


Explanation : Protected members are visible to its block and to the derived classes and not visible to outside objects or variables.

A)
It will copy the values of the variable
B)
It allows the data member to change within a const member function
C)
It allows the data member to change outside a const member function
D)
It will not allow the data member to change within a const member function

Correct Answer : Option (B) :   It allows the data member to change within a const member function


Explanation :

The mutable keyword allows the data member of a class to change within a const member function.
 
It allows to assign the values to a data member belonging to a class defined as “Const” or constant.
 
It allows a const pointer to change members.
 
It can be only applied to non-static and non-const data members of a class.

A)
Information about the functions
B)
Information about the given block
C)
Information about the variables
D)
Information about an object’s data type at runtime

Correct Answer : Option (D) :   Information about an object’s data type at runtime


Explanation : Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves. This caused incompatibilities between libraries.

A)
Used to hold the type information returned by the static_id
B)
Used to hold the type information returned by the static_cast
C)
Used to hold the type information returned by the typeid operator
D)
Used to hold the type information returned by the dynamic_cast

Correct Answer : Option (C) :   Used to hold the type information returned by the typeid operator


Explanation : type_info is used to hold the type information returned by the typeid operator.

A)
Compile-time construct
B)
Runtime construct
C)
Runtime deconstruct
D)
Both Compile-time & Runtime construct

Correct Answer : Option (A) :   Compile-time construct


Explanation : Static_cast can be applied to only compile-time construct and not during run time construct.

A)
Static members of class objects
B)
Non-static members of class objects
C)
Dynamic members of class objects
D)
Referring to whole class

Correct Answer : Option (B) :   Non-static members of class objects


Explanation : We cannot use a pointer to member to point to a static class member because the address of a static member is not associated with any particular object.

A)
It is a sequence container that encapsulates dynamic size arrays
B)
It manages the memory
C)
It manages the length and size
D)
It is a sequence container that encapsulates static size arrays

Correct Answer : Option (A) :   It is a sequence container that encapsulates dynamic size arrays


Explanation : Vector in the container library contains sequence container that manipulates and encapsulates dynamic size arrays.

242 .
What will be the output of the following C++ code?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main()
    {
        vector<int> v;
        v.assign( 10, 42 );
        for (int i = 0; i < v.size(); i++) 
        {
            cout << v[i] << " ";
        }
    }
A)
42
B)
42 42
C)
424
D)
42 for 10 times

Correct Answer : Option (D) :   42 for 10 times


Explaination :

In this program, We used the vector to print the 42 for 10 times.
Output :
$ g++ std.cpp
$ a.out
42 42 42 42 42 42 42 42 42 42

A)
Memory interface
B)
Storage interface
C)
Allocator interface
D)
Memory management

Correct Answer : Option (C) :   Allocator interface


Explanation : Allocator interface in the container is required for storage management.

A)
Memory storage locations
B)
Contiguous storage locations
C)
Non-contiguous storage locations
D)
Contiguous & Non-contiguous storage locations

Correct Answer : Option (B) :   Contiguous storage locations


Explanation : Vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements

A)
Using Single & Double linked list
B)
Using Single linked list
C)
Using linear linked list
D)
Using Double linked list

Correct Answer : Option (D) :   Using Double linked list


Explanation : List containers are implemented as doubly-linked lists. Doubly linked lists can store each of the elements they contain in different and unrelated storage locations.

A)
multimap
B)
map
C)
set
D)
unordered map

Correct Answer : Option (A) :   multimap


Explanation : C++ provide multimap container that is used to make map that can contain same keys i.e. {a: 5} and {a:10} both can exist.

A)
Memory interface
B)
Restricted interface
C)
More interface
D)
No interface

Correct Answer : Option (B) :   Restricted interface


Explanation : A container adapter provides a restricted interface to a container.In particular, adapters do not provide iterators; they are intended to be used only through their specialized interfaces.

A)
Arrays
B)
Static arrays
C)
Associative arrays
D)
Functional Arrays

Correct Answer : Option (C) :   Associative arrays


Explanation : Associative containers refer to a group of class templates in the standard library of the C++ programming language that implements ordered associative arrays.

A)
functional iterators
B)
Single directional iterators
C)
Bi-directional iterators
D)
Single & Bi-directional directional iterators

Correct Answer : Option (C) :   Bi-directional iterators


Explanation : Bi-directional iterator are used to move in both direction from any element i.e. both forward and backward movements are allowed.

A)
Generic
B)
Polymorphic
C)
Virtual
D)
Both Polymorphic & Generic

Correct Answer : Option (A) :   Generic


Explanation : The STL is a generic library, meaning that its components are heavily parameterized.

A)
Outside the block
B)
Whole program
C)
Everywhere
D)
Only on that container

Correct Answer : Option (D) :   Only on that container


Explanation : A Container “owns” its elements: the lifetime of an element stored in a container cannot exceed that of the Container itself.

A)
Objects
B)
Pointers
C)
Values
D)
Methods

Correct Answer : Option (B) :   Pointers


Explanation : Pointers are legal iterators, so if your internal container is a simple C array, then all you need to do is return the pointers.

A)
Container interface requirements
B)
Iterator requirements
C)
Allocator interface requirements
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : These are the design specific requirements for building a container from the scratch.

A)
Iterator management
B)
Memory management
C)
Storage management
D)
Storage & Memory management

Correct Answer : Option (C) :   Storage management


Explanation : Storage management is the use of the allocator interface in the user-defined container.

A)
Heterogeneous container
B)
Homogeneous container
C)
Sequence container
D)
None of the above

Correct Answer : Option (A) :   Heterogeneous container


Explanation : Heterogeneous container is the name of the container which contains group of multiple objects.

A)
array<type,size> arr;
B)
Array<type,size> arr;
C)
array<type> arr;
D)
Array<type> arr;

Correct Answer : Option (A) :   array<type,size> arr;


Explanation : The declaration of array class starts with a keyword array followed by <> specifying the type and size of array and then the name of the identifier. Example: array<int, 10> arr; arr is an array class of type in with size = 10.

A)
at() is a member function of array class whereas get() is not
B)
get() takes array class as a parameter whereas at() takes a constant integer(i.e. index) as a parameter
C)
at() is available under <array> header file whereas get() is available under <tuple> header file
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : get() and at() differ in various ways. get() is not a part of array class, get is available under <tuple> header and get() takes array class also as a parameter to access the element.

A)
Swaps two elements of an array given elements
B)
Swaps two elements given indices of elements
C)
Swaps two arrays
D)
Swaps same elements of the array if required

Correct Answer : Option (C) :   Swaps two arrays


Explanation : swap() function is used to swap elements of two array classes provided the size of both arrays classes are same.

A)
To check whether an array is empty or not
B)
To check whether the size of an array is zero or not
C)
To check how many elements are there in the array
D)
To check whether an array contains negative elements or not

Correct Answer : Option (B) :   To check whether the size of an array is zero or not


Explanation : empty() function is used to check whether the size of an array class is zero or not. It is not used to check whether an array is empty or not. The function true only if size/max_size of an array is zero otherwise it returns false.

A)
both are same
B)
begin() returns returns first element cbegin() returns void
C)
begin() returns iterator to first element and cbegin() returns iterator to last element
D)
begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element

Correct Answer : Option (D) :   begin() returns an iterator to first element whereas cbegin() returns constant iterator to first element


Explanation : Both begin() and cbegin() are used to access the first element of the vector. The function begin() returns an iterator to first element whereas cbegin() returns a constant iterator to first element.

A)
begin() returns an iterator to the first element and rbegin() returns an iterator to an element kept at the end of the vector
B)
begin() returns an iterator to first element whereas rbegin() returns constant iterator to first element
C)
begin() returns returns first element rbegin() returns void
D)
both are the same

Correct Answer : Option (A) :   begin() returns an iterator to the first element and rbegin() returns an iterator to an element kept at the end of the vector


Explanation : begin() is used to return the iterator to the first element of the vector whereas rbegin() is used to return the an element stored at in the last of a vector.

A)
v.capacity()
B)
v.size()
C)
v.max_size()
D)
v.no_of_elements()

Correct Answer : Option (B) :   v.size()


Explanation : To get the number of elements stored in the vector v we use the function v.size(). It returns how many elements are currently in the vector excluding the void places.

A)
A simple sequence of array
B)
Doubly Linked List
C)
Singly Linked List
D)
Both type of list

Correct Answer : Option (C) :   Singly Linked List


Explanation : Forward_list sequence container implements a Singly Linked List.

264 .
What will be the output of the following C++ code?
#include <iostream> 
#include <vector> 
#include <forward_list>  
 
using namespace std; 
 
int main() 
{ 
    forward_list<int> fl1 = {1,7,8,9,10};
    forward_list<int> fl2 = {2,3,4,5,6};
    fl1.splice_after(fl1.begin(), fl2);
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    return 0; 
}
A)
1 2 3 4 5
B)
2 3 4 5 6
C)
1 7 8 9 10
D)
1 2 3 4 5 6 7 8 9 10

Correct Answer : Option (D) :   1 2 3 4 5 6 7 8 9 10


Explaination :

splice_after() function is used to insert a forward-list into another list after a given position. So in this program we are trying to insert list2 into list1 after fl1.bein() i.e. 1. Hence the list1 becomes 1 2 3 4 5 6 7 8 9 10.
Output :
$ ./a.out 
1 2 3 4 5 6 7 8 9 10

A)
Belongs-to relationship
B)
Part-Of relationship
C)
Is-A relationship
D)
Has-A relationship

Correct Answer : Option (C) :   Is-A relationship


Explanation : Inheritance models Is-A type of relationship between classes. This is because in this case derived class inherits all property of the base class and Is-A type of B class.

A)
To increase code re-usability
B)
To use the functionality of one class into other
C)
To enhance the communication between classes
D)
All of the mentioned

Correct Answer : Option (D) :   All of the mentioned


Explanation : Relationships are needed to increase the use of features of one class into the other classes i.e. increasing the re-usability of codes and increasing communication between classes.

A)
Has-A relationship
B)
Have-A relationship
C)
Is-A relationship
D)
Part-Of relationship

Correct Answer : Option (A) :   Has-A relationship


Explanation : Aggregation models the has-a relationship between classes. In this children can exist without a parent, therefore, they have a relationship.

A)
All bits are set to 0 in a bitset
B)
All bits are set to 1 in a bitset
C)
First bit is set to 0
D)
All alternate bits are set to 0 in a bitset

Correct Answer : Option (A) :   All bits are set to 0 in a bitset


Explanation : When no argument is supplied to reset() function i.e. function is called with empty parameters then all the bits of the bitset is set to 0.

A)
Used to check the type of any variable
B)
Used to change the object any container is holding
C)
Used to empty any container value
D)
Used to add more item to the any list

Correct Answer : Option (B) :   Used to change the object any container is holding


Explanation : emplace() function is used to change the object contained in any container i.e destroying the present object and creating the new object for the value given by the user.

A)
Used to check whether a container is empty or not
B)
Used to destroys the contained object in any variable
C)
Used to change the object any container is holding
D)
Used to return the type information about the any container

Correct Answer : Option (D) :   Used to return the type information about the any container


Explanation : type() function is used to check the type of data/value the container object is holding.

A)
Used to empty any container value
B)
Used to check the type of any variable
C)
Used to destroys the contained object in any variable
D)
Used to change the object any container is holding

Correct Answer : Option (C) :   Used to destroys the contained object in any variable


Explanation : reset() function is provided with any to destroy an object contained in any variable in case it is not needed.

A)
To sort the elements in the heap into ascending order
B)
To sort the first half of the heap
C)
To sort the second half of the heap
D)
To sort the elements in the heap into descending order

Correct Answer : Option (A) :   To sort the elements in the heap into ascending order


Explanation : C++ STL-heap container provides sort_heap() function to sort the heap into ascending order which will no longer remain a heap.

A)
Lookup table to resolve function calls in static manners
B)
Lookup table to check how many functions are there int he program
C)
Lookup table to resolve function calls in dynamic manners
D)
Lookup table to see which are the functions available for calls throughout the program

Correct Answer : Option (C) :   Lookup table to resolve function calls in dynamic manners


Explanation : vtable is a lookup table that is used to resolve the function calls in dynamic/late binding manners.

A)
A hidden pointer in a class that points to virtual functions of that class
B)
A hidden pointer in a class that points to a virtual table of that class
C)
A pointer in a class that points to other class
D)
A hidden pointer in a class that points to virtual members of the class of that class

Correct Answer : Option (B) :   A hidden pointer in a class that points to a virtual table of that class


Explanation : This vtable pointer or _vptr, is a hidden pointer added by the compiler to the base class and this pointer is pointing to the virtual table of that particular class. This _vptr is inherited to all the derived classes. Each object of a class with virtual functions transparently stores this _vptr.

A)
An object that generates the smallest number from a given range
B)
An object that generates unique numbers
C)
An object that generates a number from a given sequence
D)
An object that generates uniformly distributed numbers

Correct Answer : Option (D) :   An object that generates uniformly distributed numbers


Explanation : Generators are objects that generates uniformly distributed numbers which help in generating random numbers.

A)
Uses user input for random number generation
B)
Uses initial seed based algorithm to generate random numbers
C)
Random number generates depends on the program
D)
Uses an algorithm that does not require any initial seed to generate random numbers

Correct Answer : Option (B) :   Uses initial seed based algorithm to generate random numbers


Explanation : Pseudo-random number engines are used to generate random numbers based on an initial seed provided to them.

A)
A generator that generates non-deterministic random numbers
B)
A generator that generates a simple random number
C)
A generator that generates deterministic random numbers
D)
A generator that generates both non-deterministic random numbers and deterministic random numbers

Correct Answer : Option (A) :   A generator that generates non-deterministic random numbers


Explanation : Random number generator is a random number generator which generates non-deterministic random numbers.

A)
Random number engine that generates pseudo-random numbers
B)
Class template that adopts a pseudo-random number generator engine
C)
Class template that adopts a pseudo-random number generator engine to produce numbers with a given numbers of bits
D)
Mersenne Twister 19937 generator generating 32-bit true random number

Correct Answer : Option (C) :   Class template that adopts a pseudo-random number generator engine to produce numbers with a given numbers of bits


Explanation : Engine adaptor is a class template that adapts a pseudo-random number generator to produce random number having a specific number of bits.

A)
To check if two variable is of array type or not
B)
To check if a variable is array type or not
C)
To check whether two variables have the same characteristics
D)
To check whether two variables are different or not

Correct Answer : Option (C) :   To check whether two variables have the same characteristics


Explanation : is_same() function is used to check whether two variables have the same characteristics or not.

A)
Objects that can hold a single element of complex type
B)
Objects that can hold more than one element of the same types
C)
Objects that can hold a single element of fundamental type
D)
Objects that can hold more than one element of different types

Correct Answer : Option (D) :   Objects that can hold more than one element of different types


Explanation :

A tuple is an object that can hold a number of elements. The elements can be of different data types. The elements of tuples are initialized as arguments in order in which they will be accessed.
 
Operations on tuple :
 
1. get() : get() is used to access the tuple values and modify them, it accepts the index and tuple name as arguments to access a particular tuple element.
 
2. make_tuple() : make_tuple() is used to assign tuple with values. The values passed should be in order with the values declared in tuple.
 
3. tuple_size : It returns the number of elements present in the tuple.
 
4. swap() : The swap(), swaps the elements of the two different tuples.
 
5. tie() : The work of tie() is to unpack the tuple values into separate variables. There are two variants of tie(), with and without “ignore” , the “ignore” ignores a particular tuple element and stops it from getting unpacked.
 
6. tuple_cat() : This function concatenates two tuples and returns a new tuple.

A)
To delete an element
B)
To access an element of a tuple
C)
To print an element of a tuple
D)
To check whether the element of the tuple is empty

Correct Answer : Option (B) :   To access an element of a tuple


Explanation : get() function is provided with header file to access an element of a tuple.

A)
Used to calculate the projection of a complex number
B)
Used to calculate the argument of a complex number
C)
Used to calculate the conjugate of a complex number
D)
Used to calculate the negative of a complex number

Correct Answer : Option (A) :   Used to calculate the projection of a complex number


Explanation :

The proj() function is a built-in function and is defined in the complex header file. This function is used to find the projection of complex number z onto the Riemann sphere.
 
Syntax :
template <class T> complex<T> 
proj (const complex<T>& z);

A)
Returns the summation of all elements of the Valarray
B)
Applies the manipulation provided to all the elements of the array
C)
Returns new array after shifting elements by the given number
D)
Returns new array after circular shifting elements by the given number

Correct Answer : Option (B) :   Applies the manipulation provided to all the elements of the array


Explanation : <Valarray> header provides apply() function to apply any manipulation passed to the function to all the elements in the Valarray.

A)
Vector of bools
B)
Template class
C)
An array of bools consuming one bit per element
D)
C-like arrays of bool elements

Correct Answer : Option (C) :   An array of bools consuming one bit per element


Explanation :

Bitset represents a fixed-size sequence of N bits and stores values either 0 or 1. Zero means value is false or bit is unset and one means value is true or bit is set. Bitset class emulates space efficient array of boolean values, where each element occupies only one bit.
 
As it emulates array, its index also starts from 0th position. Individual bit from bitset can be accessed using subscript operator. For instance to access first element of bitset foo use foo[0].
 
Bitset class provides constructors to create bitset from integer as well as from strings. The size of the bitset is fixed at compile time. STL provides vector<bool> class that provides dynamic resize functionality.
 
 
Below is definition of std::bitset from <bitset> header file
 
template <size_t N> class bitset;

A)
library
B)
iterator
C)
container
D)
algorithm

Correct Answer : Option (D) :   algorithm


Explanation : C++ Standard Library, algorithms are components that perform algorithmic operations on containers and other sequences. For this operation, We have to use <algorithm> header file.

286 .
 What will be the output of the following C++ code?
    #include <iostream> 
    #include <algorithm>
    using namespace std;
    int main () 
    {
        int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};  
        int* pbegin = myints;                      
        int* pend = myints + sizeof(myints) / sizeof(int);
        pend = remove (pbegin, pend, 20);      
        for (int* p = pbegin; p != pend; ++p)
            cout << ' ' << *p;
        return 0;
    }
A)
10, 30, 30, 10, 10
B)
10, 20, 20, 10, 10, 10, 20
C)
10, 20, 20, 10, 30, 10, 15
D)
10, 20, 30, 30, 20, 10, 10, 20

Correct Answer : Option (A) :   10, 30, 30, 10, 10


Explaination :

In this program, We are removing all the 20’s and then we are printing the remaining.

Output :
$ g++ sla4.cpp
$ a.out
10, 30, 30, 10, 10

A)
Marks the begining of a sequence
B)
Marks the ending of a sequence
C)
Marks the elements in a sequence
D)
Marks the digits in a sequence

Correct Answer : Option (C) :   Marks the elements in a sequence


Explanation : Forward iterator pointing to the element within the range and that can be moved to the first position in the range.

A)
Class template
B)
Function template
C)
Iterator
D)
Method

Correct Answer : Option (B) :   Function template


Explanation : It is a group of functions and implemented under algorithm header file.

A)
To find all the combination of the range
B)
To find all the values in the range
C)
To delete all the values
D)
To find all the values & combination in the range

Correct Answer : Option (A) :   To find all the combination of the range


Explanation : The permutation is used to find all the combination of numbers in the range.

A)
vector_permutation.h
B)
vector_permutation
C)
vector_perm
D)
<algorithm>

Correct Answer : Option (D) :   <algorithm>


Explanation : To use permutation on a vector we can use the “next_permutation” function defined in the header.

A)
Object pointer
B)
Memory pointer
C)
Class pointer
D)
Memory & Class pointer

Correct Answer : Option (A) :   Object pointer


Explanation : Because of this, It can serve as any category of iterator.

A)
Point to an element
B)
Sequence of an element
C)
Reference to an element
D)
Quantities of element

Correct Answer : Option (C) :   Reference to an element


Explanation :

free() function is used to free the memory used by the program.

Ex : 
int *p = (int*) malloc(sizeof(int)); //allocation of memory.
free(p); // freeing the memory occupied by pointer p.

A)
Raises an error
B)
It can be used
C)
It cannot be used
D)
It can’t be created

Correct Answer : Option (B) :   It can be used


Explanation : An empty string is a character array with the NULL character in the zeroth index position.

A)
Returns a different value but they are same
B)
Returns a different value
C)
Returns a length
D)
They are same

Correct Answer : Option (D) :   They are same


Explanation : Both of them will return the length of strings in the same notations.

A)
Writes to a file
B)
delete a file
C)
Reads from a file
D)
Writes to a file & Reads from a file

Correct Answer : Option (A) :   Writes to a file


Explanation : ofstream : This data type represents the output file stream and is used to create files and to write information to files.

A)
1
B)
2
C)
3
D)
4

Correct Answer : Option (C) :   3


Explanation : There are three output stream classes in c++. They are ostream, ofstream and ostrstream.

A)
BY pressing blank space
B)
BY pressing delete space
C)
After pressing return key
D)
After pressing return key & BY pressing blank space

Correct Answer : Option (C) :   After pressing return key


Explanation : When you give some input to console the processing of the input starts when the user presses enter/return key.

A)
Indicate the variable
B)
Indicate the base used
C)
Indicate the derived
D)
Indicate the base used & variable

Correct Answer : Option (B) :   Indicate the base used


Explanation : showbase is used to indicate the base used.

299 .
What will be the output of the following C++ code?
#include <iostream>
    using namespace std;
    int main ()
    {
        int a = 300;
        double b = 5.12;
        cout << a;
        cout << endl;
        cout << b << endl << a * b;
        endl (cout);
        return 0;
    }​
A)
300
B)
5.12
C)
1536
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explaination :

In this program, We are printing the given value and manipulating the given value by using endl.

Output :
300
5.12
1536

A)
fclose
B)
fopen
C)
copy
D)
compare

Correct Answer : Option (A) :   fclose


Explanation : fclose() is used to close the file and flush it out of memory for safe closing of files opened during the execution of program. In short to avoid memory faults during the execution of the program.

A)
Minimum float value
B)
Minimum finite value
C)
Maximum finite value
D)
Maximum finite value for a float type

Correct Answer : Option (D) :   Maximum finite value for a float type


Explanation : Max function in the numeric limit will return the maximum finite value for a float type.

302 .
What will be the output of the following C++ code?
    #include <iostream>
    #include <limits>
    using namespace std;
    int main () 
    {
        cout << boolalpha;
        cout << numeric_limits<int> :: has_infinity << '\n';
        return 0;
    }
A)
true
B)
false
C)
32564
D)
53234

Correct Answer : Option (B) :   false


Explaination :

In this program, We are checking whether the integer has limit or not by using has_infinity function.

Output :

false

A)
math
B)
maths
C)
cmath
D)
dmath

Correct Answer : Option (C) :   cmath


Explanation : #include is a header file required for manipulation of math functions.

A)
math
B)
cmath
C)
dmath
D)
vmath

Correct Answer : Option (D) :   vmath


Explanation : vmath is set of C++ classes for Vector and Matrix algebra used in the programs.

A)
Returns the number & result
B)
Returns the result of accumulating all the values in the range
C)
Return the characters
D)
Returns the number

Correct Answer : Option (B) :   Returns the result of accumulating all the values in the range


Explanation : Returns the result of accumulating all the values in the range from first to last.

A)
Difference
B)
Addition
C)
Subtraction
D)
Multiplication

Correct Answer : Option (A) :   Difference


Explanation : The default operation is to calculate the difference, but some other operation can be specified as binary operator instead.

A)
A technique of C++ that allows us to write overloaded functions
B)
A technique of C++ that allows us to write inline functions without a name
C)
A technique of C++ that allows us to write functions without parameters
D)
A technique of C++ that allows us to write functions that are called more than once

Correct Answer : Option (B) :   A technique of C++ that allows us to write inline functions without a name


Explanation : Lambda expression is a technique available in C++ that helps the programmer to write inline functions that will be used once in a program and so there is no need of providing names top them. Hence they are a type of inline functions without names.

A)
[X, Y]
B)
[X, &y]
C)
[&X, Y]
D)
[&x, &Y]

Correct Answer : Option (C) :   [&X, Y]


Explanation : In order to capture a variable by reference we use & operator whereas when we capture a single variable by value then we just write the name of that variable without any operator preceding it, So the correct way of capturing the variables X and Y, in this case, is [&X, Y].

309 .
What will be the output of the following C++ code?
 
#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [&]() 
        {
		a = 25;
	};
	check();
	cout<<"Value of a: "<<a<<endl;
	return 0;
}
A)
Value of a: 5
B)
Value of a: 15
C)
Value of a: 20
D)
Value of a: 25

Correct Answer : Option (D) :   Value of a: 25


Explaination : As this lambda expression is capturing the extrenal variable by reference therefore the change in value of a will be reflected back outside the expression therefore the value of a will now be 25 and 25 is printed.

A)
Arguments passed to any function
B)
Arguments passed to class functions
C)
Arguments passed to structure functions
D)
Arguments passed to main() function

Correct Answer : Option (D) :   Arguments passed to main() function


Explanation :

The most important function of C/C++ is main() function. It is mostly defined with a return type of int and without parameters :
 
int main() { /* ... */ } 
 
We can also give command-line arguments in C and C++. Command-line arguments are given after the name of the program in command-line shell of Operating Systems.

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
 
int main(int argc, char *argv[]) { /* ... */ }
or
int main(int argc, char **argv) { /* ... */ }

A)
List of command line arguments
B)
Stack of command line arguments
C)
Number of command line arguments
D)
Dictionary of command line arguments

Correct Answer : Option (C) :   Number of command line arguments


Explanation : The first argument of the main() function represents the number of command line arguments that are passed.

A)
argv[0]
B)
argv[1]
C)
argv[2]
D)
argv[3]

Correct Answer : Option (A) :   argv[0]


Explanation : The first string in the list of command line arguments represents the name of the program which can be accessed by using argv[0].

A)
int main(int argc, char **argv);
B)
int main(int argc, char const **argv);
C)
int main(int argc, char const *argv[]);
D)
All of the above

Correct Answer : Option (D) :   All of the above


Explanation : Any of the above signature can be used while using command line arguments in C++ programs