Question 1
Who invented C++?
1
Bjarne Stroustrup
2
Brian Kernighan
3
Dennis Ritchie
4
Ken Thompson
Question 2
What is C++?
1
C++ supports both procedural and object-oriented programming
2
C++ is a procedural programming language
3
C++ is a functional programming language
4
C++ is an object-oriented programming language
Question 3
Which of the following is the correct syntax of including a user defined header files in C++?
1
#include <userdefined>
2
#include <userdefined.h>
3
#include “userdefined”
4
#include [userdefined]
Question 4
Which of the following extension is used for user-defined header file in c++?
1
hg
2
cpp
3
hf
4
h
Question 5
Which of the following is a correct identifier in C++?
1
49var_name
2
47VarName
3
$var_123
4
VAR_567
Question 6
Which of the following is not a type of Constructor in C++?
1
Friend constructor
2
Default constructor
3
Parameterized constructor
4
Copy constructor
Question 7
Which of the following approach is used by C++?
1
Top-Down
2
Right-Left
3
Bottom-up
4
Left-right
Question 8
Which of the following is the correct syntax to declare a pointer in C++?
1
*int pointer;
2
pointer int*;
3
int* ptr;
4
int ptr*;
Question 9
What is the correct way to declare an array of 10 integers in C++?
1
int arr = new int[10];
2
array int arr[10];
3
int arr(10);
4
int arr[10];
Question 10
What is virtual inheritance in C++?
1
C++ technique to avoid multiple inheritances of classes
2
C++ technique to avoid multiple copies of the base class into children/derived class
3
C++ technique to enhance multiple inheritance
4
C++ technique to ensure that a private member of the base class can be accessed somehow
Question 11
What happens if the following C++ statement is compiled and executed?
int *ptr = NULL; delete ptr;
1
The program is not semantically correct
2
The program gives a compile-time error
3
The program compiled successfully but throws an error during run-time
4
The program is compiled and executed successfully
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
dev brainiac
2
dev
3
devbrainiac
4
error
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
Error in C++ and successful execution in C
2
Error in both C and C++
3
Error in C and successful execution in C++
4
A successful run in both C and 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
Error in both C and C++
2
Error in C and successful execution in C++
3
Error in C++ and successful execution in C
4
Outputs devbrainiac twice in both C and 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 the functions of a class
2
this pointer is passed as a hidden argument in all static variables of a class
3
this pointer is passed as a hidden argument in all non-static functions 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
c++ output prediction
3
coutputprediction
4
++
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
2
c++outputprediction
3
c++
4
c++ output prediction
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 123 c++ 78 code
3
hellow c++ code
4
hellow c 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
error
3
16
4
15
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
15
2
error
3
17
4
16
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
15
2
16
3
error
4
17
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
error
2
16
3
15
4
17
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
17
2
15
3
16
4
30
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
30
2
17
3
16
4
15
Question 26
By default, all the files in C++ are opened in _________ mode.
1
VTC
2
Binary
3
ISCII
4
Text
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
Runtime error may be possible
2
0
3
Compiler error may be possible
4
1
Question 28
Which of the following correctly declares an array in C++?
1
array{10};
2
int array;
3
int array[10];
4
array 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
cin: garbage value
2
Nothing is printed
3
Segmentation fault
4
error
Question 30
Which is more effective while calling the C++ functions?
1
call by value
2
call by pointer
3
call by reference
4
call by object