Question 1
Who invented C++?
1
Ken Thompson
2
Dennis Ritchie
3
Brian Kernighan
4
Bjarne Stroustrup
Question 2
What is C++?
1
C++ is an object-oriented programming language
2
C++ is a procedural programming language
3
C++ supports both procedural and object-oriented programming
4
C++ is a functional programming language
Question 3
Which of the following is the correct syntax of including a user defined header files in C++?
1
#include <userdefined.h>
2
#include [userdefined]
3
#include <userdefined>
4
#include “userdefined”
Question 4
Which of the following extension is used for user-defined header file in c++?
1
hf
2
h
3
cpp
4
hg
Question 5
Which of the following is a correct identifier in C++?
1
47VarName
2
VAR_567
3
$var_123
4
49var_name
Question 6
Which of the following is not a type of Constructor in C++?
1
Copy constructor
2
Parameterized constructor
3
Default constructor
4
Friend constructor
Question 7
Which of the following approach is used by C++?
1
Left-right
2
Bottom-up
3
Top-Down
4
Right-Left
Question 8
Which of the following is the correct syntax to declare a pointer in C++?
1
int ptr*;
2
int* ptr;
3
*int pointer;
4
pointer int*;
Question 9
What is the correct way to declare an array of 10 integers in C++?
1
int arr[10];
2
int arr = new int[10];
3
array int arr[10];
4
int arr(10);
Question 10
What is virtual inheritance in C++?
1
C++ technique to avoid multiple copies of the base class into children/derived class
2
C++ technique to ensure that a private member of the base class can be accessed somehow
3
C++ technique to enhance multiple inheritance
4
C++ technique to avoid multiple inheritances of classes
Question 11
What happens if the following C++ statement is compiled and executed?
int *ptr = NULL; delete ptr;
1
The program compiled successfully but throws an error during run-time
2
The program is compiled and executed successfully
3
The program is not semantically correct
4
The program gives a compile-time error
Question 12
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 s1[6] = "dev";
char s2[6] = "brainiac";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}1
error
2
dev
3
devbrainiac
4
dev brainiac
Question 13
What is the difference between delete and delete[] in C++?
1
delete is used to delete normal objects whereas delete[] is used to pointer objects
2
delete is used to delete single object whereas delete[] is used to multiple(array/pointer of) objects
3
delete is a keyword whereas delete[] is an identifier
4
delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
Question 14
What happens if the following program is executed in C and C++?
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}1
A successful run in both C and C++
2
Error in C and successful execution in C++
3
Error in both C and C++
4
Error in C++ and successful execution in C
Question 15
What will happen if the following program is executed in both C and C++?
#include <stdio.h>
void func(void)
{
printf("devbrainiac");
}
void main()
{
func();
func(2);
}1
Outputs devbrainiac twice in both C and C++
2
Error in C and successful execution in C++
3
Error in both C and C++
4
Error in C++ and successful execution in C
Question 16
Which of the following is correct about this pointer in C++?
1
this pointer is passed as a hidden argument in all non-static functions of a class
2
this pointer is passed as a hidden argument in all the functions of a class
3
this pointer is passed as a hidden argument in all static variables of a class
4
this pointer is passed as a hidden argument in all static functions of a class
Question 17
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s = "c++ output prediction";
s.erase(remove_if(s.begin(), s.end(), [](char c) { return c == ' ' || c == '+'; }), s.end());
cout << s << endl;
}1
c++outputprediction
2
++
3
c++ output prediction
4
coutputprediction
Question 18
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s = "c++ output prediction";
s.erase(remove(s.begin(), s.end(), ' ' ),s.end());
cout << s << endl;
}1
c++ output prediction
2
c++output
3
c++
4
c++outputprediction
Question 19
What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s = "hellow 123 c++ 78 code";
s.erase(remove_if(s.begin(), s.end(), [](char c) { return isdigit(c); }), s.end());
cout << s << endl;
}1
hellow123c++78code
2
hellow c++ code
3
hellow c code
4
hellow 123 c++ 78 code
Question 20
What will be the output of 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;
}1
17
2
16
3
15
4
error
Question 21
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = true;
int x = 10;
int y = 5;
p = ((x | y) + (a + b));
cout << p;
return 0;
}1
error
2
16
3
15
4
17
Question 22
What will be the output of 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 + a) + (y + b));
cout << p;
return 0;
}1
17
2
15
3
16
4
error
Question 23
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 11;
int y = 4;
p = ((x | a) + (y + b));
cout << p;
return 0;
}1
17
2
15
3
error
4
16
Question 24
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int p;
int a = 10;
int b = 5;
int x = 11;
int y = 4;
p = ((x | a) + (y | b));
cout << p;
return 0;
}1
30
2
17
3
16
4
15
Question 25
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int a = 10, b = 5, x = 11, y = 4;
int p = ((x | a) + y | b);
cout << p;
return 0;
}1
17
2
16
3
15
4
30
Question 26
By default, all the files in C++ are opened in _________ mode.
1
Text
2
Binary
3
VTC
4
ISCII
Question 27
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}1
Compiler error may be possible
2
0
3
Runtime error may be possible
4
1
Question 28
Which of the following correctly declares an array in C++?
1
int array;
2
int array[10];
3
array array[10];
4
array{10};
Question 29
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
int cin;
cin >> cin;
cout << "cin: " << cin;
return 0;
}1
Nothing is printed
2
error
3
Segmentation fault
4
cin: garbage value
Question 30
Which is more effective while calling the C++ functions?
1
call by pointer
2
call by reference
3
call by object
4
call by value
