1. What is the difference between a deep copy and a shallow copy in C++?
2. Which of the following is possible in c++?
3. Why pre-increment is faster than post-increment in C++?
4. What is the size of an object of an empty class in C++?
5. How many types of templates are there in C++?
6. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main () { char str1[10] = "Hello"; char str2[10] = "World"; char str3[10]; int len ; strcpy( str3, str1); strcat( str1, str2); len = strlen(str1); cout << len << endl; return 0; }
7. Predict the output : 2 #include <bits/stdc++.h> using namespace std; void doo(vector<int> arr, int n) { for (int i = 0 ; i < n ; i++) arr[i] = arr[i] * 3; } int main() { vector<int> nums = {1, 2, 3, 4, 5}; doo(nums, 5); int sum = 0; for (int i = 0 ; i < 5 ; i++) sum += nums[i]; cout << sum << "\n"; return 0; }
8. What is the correct syntax for using smart pointers in C++? (Assume header files are already included)
9. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main() { int arr[][] = {{1,2},{3,4}}; int i, j, sum = -10; for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) sum += arr[i][j]; cout << sum; return 0; }
10. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main() { int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0; for (n = 0 ;n < 7 ;n++){ result += array[n]; } cout << result; return 0; }
11. What is the correct way to initialize a vector in C++?
12. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main () { string str ("Microsoft"); for (size_t i = 0; i < str.length();) { cout << str.at(i-1); } return 0;
13. Predict the output : 3 #include <bits/stdc++.h> using namespace std; void doo(int arr[], int n) { for (int i = 0; i < n; i++) arr[i] = arr[i] * 3; } int main() { int nums[5] = {1, 2, 3, 4, 5}; doo(nums, 5); int sum = 0; for (int i = 0; i < 5 ; i++) sum += nums[i]; cout << sum << "\n"; return 0; }
14. Which of the following is a data type in c++?
15. What is the syntax for printing a message in c++?
16. When we create an object of a derived class in c++, then?
17. Consider the following definition in C++ programming language. struct node { int data; struct node * next; } typedef struct node NODE; NODE *ptr; Which of the following c code is used to create new node?
18. Which of the following code is the correct syntax for creating a class in C++?
19. Which of the following are the correct syntax for creating templates in C++? 1. template<class T> 2. template<typename T> 3. <template T> 4. template<class T, class U>
20. What is true about his statement in C++? std::vector<int> vecInts(5);
21. What is the output of the below code? #include <bits/stdc++.h> int main() { char str[] = {'a', 'b', 'c'}; std::cout << str << '\n'; return 0; }
22. What is the time complexity of concatenation of string in C++? // E.g find time complexity of below code. string str = "outscal"; str += "clan";
23. What should be filled in place of _______ to run the below code without any error? #include <bits/stdc++.h> using namespace std; int main() { string s1 = "oustcalclan"; string s2 = "clann"; size_t pos = s1.find(s2); if (pos == _______) cout << "Not Found" << '\n'; else cout << "Found" << '\n'; return 0; }
24. Predict the output: #include <bits/stdc++.h> using namespace std; int main() { char str[] = "GAME DEVELOPER"; char* token = strtok(str, " "); while (token != NULL) { cout << token << '\n'; token = strtok(NULL, " "); } return 0; } a)GAME DEVELOPER b)GAMEDEVELOPER c)GAME d)GAME DEVELOPER
25. Which of the following is correct about structure and class in C++? 1. Class members are private by default, and members of a struct are public by default. 2. When deriving a class from the base class, the default access specifier is public. 3. When deriving a class from the base class, the default access specifier is private.
26. How Encapsulation is achieved in C++?
27. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main() { int arr[] = {1,2,3,4,5}; int sum = 10; for (int i = 0 ; i < 5 ; i++) { sum += arr[i]; sum -= sum; } cout << sum; return 0; }
28. Is it possible to initialize any Vector with an Array in C++?
29. What will be the output of the following C++ code? #include <iostream> #include <vector> using namespace std; int main () { vector<int> first; first.assign (7,100); vector<int>::iterator it; it=first.begin()+1; int myints[] = {1776,7,4}; cout << int (first.size()) << '\n'; return 0; }
30. What is the output of the below code? // stoi is used to convert string into integer #include <bits/stdc++.h> using namespace std; int main() { string s = "0x10A"; cout << stoi(s, nullptr, 16) << endl; return 0; }
31. Predict the output: #include <bits/stdc++.h> using namespace std; int main() { char str[] = "abc"; cout << sizeof(str) << " " << strlen(str) << '\n'; return 0; }
32. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main() { string str {"Steve jobs"}; unsigned long int found = str.find_first_of("aeiou"); while (found != string :: npos) { str[found] = '*'; found = str.find_first_of("aeiou", found + 1); } cout << str << "\n"; return 0; }
33. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main () { string str ("microsoft"); string::reverse_iterator r; for (r = str.rbegin() ; r < str.rend(); r++ ) cout << *r; return 0; }
34. What is the output of the below code? #include <bits/stdc++.h> int main() { char str[] = "abc"; std::cout << str << '\n'; return 0; }
35. Predict the output: 1 #include <bits/stdc++.h> void fun(int n) { if (n == 0) return; std::cout << n%2; fun(n/2); } int main() { fun(25); return 0; }
36. Predict the time complexity of the below code: #include <bits/stdc++.h> using namespace std; int dp[100][100]; int matrixChainMemoised(int *p, int i, int j) { if (i == j) { return 0; } if (dp[i][j] != -1) { return dp[i][j]; } dp[i][j] = INT_MAX; for (int k = i; k < j; k++) { dp[i][j] = min( dp[i][j], matrixChainMemoised(p, i, k) + matrixChainMemoised(p, k + 1, j) + p[i - 1] * p[k] * p[j] ); } return dp[i][j]; } int main() { int arr[] = {1, 2, 3, 4}; int n = sizeof(arr) / sizeof(arr[0]); memset(dp, -1, sizeof dp); cout << matrixChainMemoised(arr, 1, n-1); return 0; }
37. Predict the output: #include <bits/stdc++.h> using namespace std; template <typename T> int solve(const vector<T> &a) { vector<T> u; for (const T &x : a) { auto it = lower_bound(u.begin(), u.end(), x); if (it == u.end()) u.push_back(x); else *it = x; } return (int)u.size(); } int main() { vector<int> arr{1, 2, 3, 4, 4, 5, 5, 7. 8. 9, 6, 7, 11}; cout << solve(arr); return 0; }
38. Predict the output: #include <bits/stdc++.h> using namespace std; int solve(vector<int>& nums) { int c = max(0,nums[0]); int m = nums[0]; for(int i=1;i<nums.size();i++){ c += nums[i]; c = max(0, c); m = max(m, c); } return m; } int main() { vector<int> arr1 = {-1, -2, -3, -4, -9}, arr2 = {-1, 1, 3, -1, 5, -2}; cout << solve(arr1) + solve(arr2); return 0; }
39. Predict the output: #include <bits/stdc++.h> using namespace std; int solve(int n) { int i, j, arr[n], k; arr[0] = 1; for (i = 1; i < n; i++) { arr[i] = 0; for (j = 0, k = i - 1; j < i; j++, k--) arr[i] += arr[j] * arr[k]; } return arr[n - 1]; } int main() { cout << solve(8); return 0; }
40. What role does the main() function play in a C++ program?
41. What is the primary purpose of cout in C++?
42. What purpose does the semicolon (;) serve at the end of most lines in C++ code?
43. What is the function of \n as a line terminator in C++?
44. Consider the following code snippet: int main() { // Single line comment /* Multi-line comment */ return 0; } Which statement about comments in C++ is accurate?
45. Which of the following statements about variable declaration in C++ is NOT true?
46. What is the correct syntax to write comments in C++? 1. # This is a comment 2. / This is a comment 3. // This is a comment 4. /* This is a new comment */
47. Which of the following is the correct way of defining a function in C++? 1. void fun() {} 2. void function(int a, int b) {} 3. int func() { return -1; } 4. int func(double x) { return 0.0; }
48. What is the size of an empty class in C++?
49. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main() { int arr[] = {1,2,3}; cout << arr[3] << " " << arr[-1] << '\n'; return 0; }
50. What is the output of the below code? #include <bits/stdc++.h> using namespace std; int main() { int arr[] = {1,2,3,4,5,6}; cout << -5[arr]; return 0; }
51. What is causing unpredictable behaviour on compilation error in the following C++ code snippet? int arr[5] = { 1,2,3,4,5 }; cout<< endl << arr[5]<<endl;
52. Consider the following C++ function int fun(int n) { int i, j; for(i = 1; i<= n; i++) { for(j=1; j<n; j += i) { cout<<i<<j; } } } Time complexity of fun in terms of θ notation is?
53. What is the difference between a class template and a function template in C++?
54. Which of the following C++ line correctly creates an instance of the Player class named player?
55. What is the purpose of a destructor in C++?
56. How is Abstraction achieved in C++?
57. What is the purpose of a header file in C++ programming?
58. Why is it important to separate code into header (.h) and source (.cpp) files?
59. You must have seen the #pragma once directive many times while working with C++ header files. Ever wondered what it does? What's the significance of the #pragma once directive?
60. What will be the output of the following C++ code? #include <iostream> using namespace std; class OutscalRectangle { int x, y; public: void setDimensions(int, int); int calculateArea() { return (x * y); } }; void OutscalRectangle::setDimensions(int a, int b) { x = a; y = b; } int main() { OutscalRectangle rectangle; rectangle.setDimensions(3, 4); cout << "The area of the rectangle is: " << rectangle.calculateArea(); return 0; }
61. What will be the output of the following C++ code? #include<iostream> int main() { const int a=10; a++; std::cout<<a; return 0; }
62. What is the difference between the pointer declarations int* numPtr; and int *numPtr; in C++?
63. Consider the line of code int *ptr = new int;. What does this statement achieve in C++ and what are the implications of using it?
64. What is the difference between using new and malloc for dynamic memory allocation in C++?
65. What happens if you try to dereference a null pointer in C++? #include <iostream> int main() { int* ptr = nullptr; std::cout << "Dereferencing a null pointer: " << *ptr << std::endl; return 0; }
66. What is the purpose of using namespaces in C++?
67. What issue can arise due to naming conflicts in C++?
68. What is "scope resolution" in the context of namespaces, and how is it used in C++?
69. Why it is important to write “using namespace std” in C++ program?
70. Consider the following C++ program and focus on the initialization of the object t3. What will be the output of the program when t3 is initialized? #include<iostream> using namespace std; class OutscalCoordinates { private: int x; int y; public: OutscalCoordinates(int i = 0, int j = 0); OutscalCoordinates(const OutscalCoordinates &t); }; OutscalCoordinates::OutscalCoordinates(int i, int j) { x = i; y = j; cout << "Coordinates of Player\n"; } OutscalCoordinates::OutscalCoordinates(const OutscalCoordinates &t) { y = t.y; cout << "Coordinates of Enemy\n"; } int main() { OutscalCoordinates *t1, *t2; t1 = new OutscalCoordinates(10, 15); t2 = new OutscalCoordinates(*t1); OutscalCoordinates t3 = *t1; return 0; }
71. What is the primary effect of the static keyword when applied to a variable inside a function in C++?
72. How does the static keyword helps in implementing the Singleton design pattern in C++?
73. What is true about the memory allocation for static variables in C++?
74. What will be the output of the following C++ program? #include <iostream> using namespace std; void counter() { static int count = 0; cout << count << " "; count++; } int main() { for (int i = 0; i < 5; i++) { counter(); } return 0; }
75. What will be the output of the following C++ program? #include <iostream> class Outscal { public: void fun(); }; static void Outscal::fun() { std::cout<<"Welcome to Outscal Games."<<endl; } int main() { Outscal::fun(); return 0; }
76. What will be the output of the following C++ program? #include <iostream> using namespace std; void process() { static int value = 10; static int* ptr = &value; cout << *ptr << " "; (*ptr)++; cout << *ptr << endl; } int main() { process(); process(); return 0; }
77. What is Inheritance in C++?
78. In C++, which real-life scenario correctly illustrates the concept of multiple inheritance?
79. How do constructors in base and derived classes affect an object’s initialization in C++?
80. Can more than one class be derived from a base class in C++?
81. Which of the following are correct about structure and class in C++? A) Class members are private by default, and members of a struct are public by default. B) When deriving a class from the base class, the default access specifier is public. C) When deriving a class from the base class, the default access specifier is private.
82. How many Access specifier are there in C++?
83. What is the output of the following C++ code? #include<iostream> using namespace std; class Country{ private: int population; public: void setPopulation(int pop){ this->population = pop; } int getPopulation(){ return this->population; } }; class USA: private Country{ }; int main(){ USA obj; obj.setPopulation(100); cout<<obj.getPopulation(); return 0; }
84. In a game developed using with C++, you have a base class Enemy and derived classes Orc and Troll. Both Orc and Troll share some methods from another class Knife. How can you design this inheritance to maintain a clean structure and avoid duplication
85. What is the order in which constructors are called when creating an object of a derived class in C++?
86. What is the primary issue caused by the diamond problem in C++ inheritance?
87. Can a virtual function be overloaded in C++?
88. What is the output of the following C++ code? #include <iostream> using namespace std; class Game{ public: virtual void func(){ cout<<"Welcome to Game\n"; } }; class OutscalGame: public Game{ public: void func(){ cout<<"Welcome to Outscal Game\n"; } }; int main() { OutscalGame ob; ob.func(); return 0; }
89. Why is it important to mark the destructor of a base class as virtual in C++?
90. How is the delta time used in the implementation of the moveDown() method in EnemyController.cpp?
91. What is the key difference between const and static variables in C++?
92. Considering the standard practice for naming interfaces in C++, how would you name the interface for a class representing a geometric shape?
93. Is it possible to define member variables inside an interface in C++?
94. How do interfaces and abstract classes differ in defining blueprints for derived classes in C++?
95. Which of the following is used to implement the C++ interfaces
96. Consider the following code snippet: cppCopy code #include <iostream>class IShape { public: virtual void draw() const = 0; }; class Circle : public IShape { public: void draw() const override { std::cout << "Drawing a circle." << std::endl; } }; class Square : public IShape { public: void draw() const override { std::cout << "Drawing a square." << std::endl; } }; int main() { const IShape* shapes[] = {new Circle(), new Square()}; for (const auto& shape : shapes) { shape->draw(); } return 0; } What will be the output of the program?
97. What is the role of static members and static member functions in a C++ interface?
98. What will be the output of the following C++ code? #include <iostream> using namespace std; class OutscalGames { public: static int value; OutscalGames() { value += 5; } void display() const { cout << "Value: " << value << endl; } }; int OutscalGames::value = 50; int main() { const OutscalGames obj; obj.display(); return 0; }
99. What will be the output of the following C++ code? #include <iostream> class Game { public: virtual void print() const { std::cout << "Game Called" << std::endl; } }; class OutscalGame : public Game { public: void print(){ std::cout << "Outscal Game Called" << std::endl; } }; int main() { const Game* ptr = new OutscalGame(); ptr->print(); delete ptr; return 0; }
100. Which of the following is the least safe type casting in C++?
101. What will be the output of the following C++ code? #include <iostream> using namespace std; class Game { float i, j; }; class OutscalGame { int x, y; public: OutscalGame (int a, int b) { x = a; y = b; } int result() { return x + y; } }; int main () { Game d; OutscalGame * padd; padd = (OutscalGame*) &d; cout<< padd->result(); return 0; }
102. What is the primary purpose of static_cast in C++?
103. What is a friend function in C++?
104. What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class TreasureChest { int capacity = 0; public: TreasureChest(int cap){ capacity = cap; } friend void revealTreasure(); }; void revealTreasure() { TreasureChest chest(10); cout << chest.capacity << endl; } int main() { revealTreasure(); }
105. In C++, can 'friend' functions access private members of a derived class?
A. A deep copy creates a completely new and independent copy of an object, while a shallow copy only copies the reference to an object
B. A shallow copy creates a completely new and independent copy of an object, while a deep copy only copies the reference to an object
C. A deep copy and a shallow copy are the same things
D. None of the above
A. Virtual constructor
B. Virtual member variables
C. Virtual functions
D. All of the above
A. The question statement is wrong, both take equal time
B. Former takes one-byte instruction while latter takes two bytes instruction
C. Former takes two bytes instruction while the latter takes one-byte instruction
D. None of the above
A. Sum of the size of all the variables within a class.
B. It is the largest size of the variable of the same class.
C. Sum of the size of all inherited variables along with the variables of the same class.
D. Size of an object of an empty class in C++ is at least 1 byte.
A. 1
B. 2
C. 3
D. 4
A. 5
B. 55
C. 11
D. 10
A. 15
B. 45
C. 40
D. Error
A. std::unique_ptr<int> p(new int);
B. std::unique_ptr<int> p[new int];
C. std::unique_ptr<int> p = new int;
D. std::unique_ptr<int> p = new int[];
A. 0
B. 10
C. Garbage Value
D. Compilation error
A. 25
B. 26
C. 27
D. 24
A. std::vector<integer> vecOfInts;
B. std::vector int <vecOfInts>
C. std::vector(int) vecOfInts;
D. std::vector<int> vecOfInts;
A. M
B. Microsoft
C. Micro
D. runtime error
A. 15
B. 45
C. 40
D. Error
A. int
B. float
C. double
D. all of the above
A. cout<<”message”;
B. cin>>"message";
C. print(”message”);
D. cout(”message”);
A. Derived class constructor is called first the base class constructor.
B. Base class constructor is called first then derived class constructor.
C. Base class constructor will not be called.
D. None of the above
A. ptr = (NODE*)malloc(sizeof(NODE));
B. ptr = (NODE*)malloc(NODE);
C. ptr = (NODE*)malloc(sizeof(NODE*));
D. ptr = (NODE)malloc(sizeof(NODE));
A. Class Test {};
B. class Test {}
C. class Test {};
D. Class Test {}
A. 1, 2
B. 1, 4
C. 1, 2, 4
D. 3
A. Initialize a Vector with 5 int & all default value is 0
B. Initialize a Vector with 5 int
C. Initialize a Vector with 5 int & all default values will be garbage
D. Initialize a Vector with 5 int & All default value with be -1
A. abc
B. abcgarbage
C. garbage
D. none of the above
A. O(1)
B. O(M) → M is the length of string to be concatenated
C. O(N) → N is the length of the original string
D. Unspecified, but generally linear
A. -1
B. string::size_t
C. s1.length()
D. string::npos
A. a)
B. b)
C. c)
D. d)
A. 1
B. 2
C. 1, 2
D. 1, 3
A. by using private members
B. by using protected Members
C. by using access specifiers
D. by using the concept of abstraction
A. 10
B. 0
C. 15
D. 25
A. Yes
B. No
A. 10
B. 9
C. 8
D. 7
A. Compilation error
B. Garbage Value
C. 266
D. 1010
A. 3 3
B. 4 3
C. 3 4
D. 4 4
A. Steve
B. jobs
C. St*v* j*bs
D. St*v*
A. microsoft
B. micro
C. tfosorcim
D. tfos
A. abc
B. abcgarbage
C. garbage
D. none of the above
A. 10011
B. 11111
C. 10111
D. 11001
A. O(n)
B. O(n^2)
C. O(n^2 log n)
D. O(n^3)
A. 9
B. 10
C. 13
D. Error
A. Compilation error
B. 8
C. 0
D. 5
A. 42
B. 132
C. 429
D. 1430
A. main() is optional in a C++ program.
B. main() is where the program execution begins.
C. main() cannot accept any arguments.
D. main() must always return a value.
A. It is a function used for getting user input.
B. It is used to display output to the console.
C. It is a keyword to declare variables.
D. It stands for "character output" in C++.
A. It signifies the end of the program.
B. It separates multiple statements within a loop.
C. It's a syntactical requirement to terminate statements.
D. It improves code readability for developers.
A. It denotes the beginning of a function block.
B. It indicates the start of a new line in the console output.
C. It's used for commenting out code lines.
D. It terminates the program's execution.
A. Multi-line comments cannot be nested within single-line comments.
B. Both single-line and multi-line comments can be nested within each other.
C. Comments can be used as a substitute for writing proper code documentation.
D. Comments have no impact on the compiled code size.
A. A variable must be declared before it can be used.
B. Variable names can start with an underscore (_).
C. The declaration and initialization of a variable must occur in the same statement.
D. Variable declarations specify the data type and name of the variable.
A. 1
B. 2
C. 3
D. 3, 4
A. 1, 2, 4
B. 1, 2, 3, 4
C. 2, 3
D. 1, 2, 3
A. Sum of the size of all the variables within a class.
B. The size of the class is the largest size of the variable of the same class.
C. Sum of the size of all inherited variables along with the variables of the same class.
D. Atleast 1 byte
A. Compilation error
B. Runtime Error
C. 0 0
D. Garbage Value Garbage Value
A. Compilation error
B. Garbage Value
C. -5
D. -6
A. There is no error; the code will print the last element of the array.
B. The array is initialized with too many elements.
C. The syntax for printing the array element is incorrect.
D. The code tries to access an element outside the bounds of the array.
A. Θ(n√n)
B. Θ(n^2)
C. Θ(nlogn)
D. Θ(n^2logn)
A. A class template is a blueprint for creating objects, while a function template is a blueprint for creating functions
B. A class template is a blueprint for creating functions, while a function template is a blueprint for creating objects
C. Both are the same
D. None of the above
A. Player player = new Player();
B. Player player();
C. Player player;
D. new Player player;
A. To initialize objects
B. To allocate memory
C. To destroy objects and free resources
D. To declare variables
A. By using private members, ensuring that data is accessible only within the class itself.
B. By using access specifiers, such as private, protected, and public, to control the visibility of class members.
C. By hiding complex implementation details and exposes only essential features.
D. By creating getter and setter methods for class variables, allowing controlled access to private data.
A. To contain the implementation code of functions
B. To include code from other scripts containing necessary declarations
C. To define the behaviour of classes and objects
D. To handle input/output operations
A. To make the program smaller by removing parts that are not used.
B. To keep things organized by using headers to list what the program does and using source files to show how it does those things.
C. To help automatically write detailed notes about the program.
D. To make the program start faster by preparing some parts of it in advance.
A. It acts as a header file guard, preventing the same header file from being included multiple times in a single compilation unit.
B. It triggers compiler optimizations, improving the compilation speed by eliminating redundant includes.
C. It allocates a fixed memory segment for header file contents, ensuring efficient memory utilization.
D. It enforces modular coding practices, adhering to strict standards and preventing code duplication.
A. The area of the rectangle is: 24
B. The area of the rectangle is: 12
C. There is a compile error because OutscalRectangle is used as both a class name and a variable name.
D. The area of the rectangle is: 56
A. 10
B. 11
C. Compilation Error
D. Syntax Error
A. int* numPtr; declares a pointer to an integer, whereas int *numPtr; declares an integer that is being dereferenced.
B. There is no difference; both statements declare a pointer to an integer.
C. int* numPtr; declares a normal integer, while int *numPtr; declares a pointer to an integer.
D. int* numPtr; declares two pointers to integers, whereas int *numPtr; declares one pointer to an integer.
A. It declares a pointer variable ptr and allocates memory for an integer, initializing it with a default value.
B. It creates a pointer ptr that directly assigns a new integer value from the heap, preventing memory leaks.
C. It allocates memory for an integer on the heap and assigns the address of this memory to the pointer ptr.
D. It initializes the pointer ptr with a random memory address and then tries to assign an integer value.
A. There is no difference; they both perform the same task.
B. new automatically calls the constructor for objects, while malloc does not.
C. malloc is used for arrays, while new is used for single objects.
D. new allocates memory on the heap, while malloc allocates memory on the stack.
A. It returns the memory address of the null pointer.
B. It leads to undefined behavior, possibly resulting in a program crash.
C. It automatically assigns a value of zero to the pointer.
D. It triggers a compile-time error.
A. To increase compile times.
B. To reduce dependency.
C. To organize code into logical groups.
D. To introduce bugs in the code.
A. Reduced code readability.
B. Increased compile times.
C. Global scope pollution.
D. Improved modularity.
A. Defines visibility boundaries for functions.
B. Manages memory for objects in namespaces.
C. Specifies which namespace an identifier belongs to, resolving name conflicts.
D. Optimizes program execution efficiency.
A. To ensure that all features of the C++ Standard Library are accessible without needing to prefix them with std::.
B. To allow direct access to the features of the C++ Standard Library, like those in <iostream>, <vector>, and more, without having to use the std:: prefix, improving code brevity and readability.
C. To automatically include all headers from the C++ Standard Library without writing multiple #include directives.
D. To increase the performance of the program by pre-loading all standard library functions into the global namespace.
A. Coordinates of Player
B. Coordinates of Enemy
C. No output as t3 is a default constructed object.
D. Compilation error due to incorrect usage of pointers.
A. It makes the variable persistent between multiple function calls.
B. It restricts the variable's scope to the inside of the block where it's declared.
C. It initializes the variable to zero.
D. It protects the variable from being modified by other functions.
A. By ensuring that multiple instances of a class can be created.
B. By enabling lazy initialization of the class’s unique instance.
C. By allowing the class instance to be duplicated using the copy constructor.
D. By providing thread-local storage for the Singleton instance.
A. static variables are stored in a special area of memory called the stack.
B. static variables are stored in the heap and persist until the program ends.
C. static variables are stored in the same area as global variables, and they persist for the lifetime of the program.
D. static variables are allocated and deallocated by the programmer using new and delete.
A. 0 0 0 0 0
B. 0 1 2 3 4
C. 1 2 3 4 5
D. 5 5 5 5 5
A. fun() is static
B. Empty Screen
C. Compiler Error
A. 10 10 10 10
B. 10 11 11 12
C. 10 10 11 11
D. Compilation Error
A. Wrapping of data into a single class
B. Deriving new classes from existing classes
C. Overloading of classes
D. Classes with same names
A. Fish Class: A Fish class inherits from Ocean and Swimmer classes
B. Electric Car Class: A Electric Car class inherits from both Vehicle and Electronics classes.
C. Motorboat Class: A Motorboat class inherits from Boat and Water classes,
D. Library Class: A Library class inherits from Book and Patron classes
A. Constructors of a derived class replace constructors from the base class, erasing the base class's properties.
B. The constructor of the base class must always be called explicitly in the derived class's constructor.
C. The base class constructor is called automatically before the derived class's constructor to ensure the whole object is properly initialized.
D. Constructors are not inherited; thus, the base class's constructor is ignored.
A. True
B. False
A. A
B. B
C. A, B
D. A, C
A. 1
B. 2
C. 3
D. 4
A. 100
B. 0
C. Compilation Error
D. Garbage Value is printed
A. The derived class constructor is called first, then the base class constructor.
B. The base class constructor is called first, then the derived class constructor.
C. Constructors are called in alphabetical order of the class names.
D. The order of constructor calls is determined at runtime.
A. Namespace pollution
B. Multiple copies of the base class are created in the derived class
C. Memory leaks
D. Increased compilation time
A. Yes, but only if it's defined in the base class.
B. No, it violates the principles of polymorphism.
C. Yes, but only if it's defined in the derived class.
D. No, virtual functions cannot be overloaded.
A. Welcome to Outscal Game
B. Welcome to Game
C. Welcome to Game Welcome to Outscal Game
D. Welcome to Outscal Game Welcome to Game
A. To improve code readability
B. To allow for function overloading
C. To ensure proper cleanup of resources in derived classes
D. To facilitate dynamic binding
A. It is added to the movement speed
B. It is subtracted from the movement speed
C. It is multiplied by the movement speed
D. It is divided by the movement speed
A. const variables cannot be modified after initialization, while static variables retain their value across function calls.
B. const variables can only be accessed within the same source file, while static variables can be accessed globally.
C. const variables are stored in read-only memory, while static variables are stored in the heap.
D. const variables are initialized at compile-time, while static variables are initialized at runtime.
A. IShape
B. ShapeInterface
C. GeometricShapeInterface
D. AbstractShape
A. Yes
B. Yes, if they are static
C. Yes, if they are const
D. No
A. Interfaces specify method declarations for derived classes to implement, while abstract classes can also include method implementations.
B. Interfaces allow for multiple inheritance, whereas abstract classes are limited to single inheritance.
C. Abstract classes impose stricter requirements on derived classes, while interfaces offer more flexibility.
D. Both serve the purpose of defining blueprints for derived classes, with interfaces focusing on method declarations and abstract classes allowing method implementations.
A. absolute variables
B. abstract classes
C. constant variables
D. default variables
A. Drawing a circle. Drawing a square.
B. Drawing a square. Drawing a circle.
C. Drawing a circle. Drawing a circle.
D. Compilation Error.
A. Providing access to class-specific data and behaviors.
B. Allowing for dynamic binding of function calls.
C. Facilitating integration of multiple inheritance.
D. Defining common behaviors through abstract methods.
A. Value: 50
B. Value: 55
C. Compilation error
D. Runtime error
A. Game Called
B. Outscal Game Called
C. Game Called Outscal Game Called
D. Outscal Game Called Game Called
A. static_cast
B. const_cast
C. reinterpret_cast
D. dynamic_cast
A. 20
B. runtime error
C. random number
D. runtime error or random number
A. It performs dynamic type checking at runtime.
B. It facilitates implicit type conversions between compatible data types.
C. It ensures type safety by preventing invalid type conversions.
D. It allows explicit type conversions between related data types at compile time.
A. A function which can access all the private, protected and public members of a class
B. A function which is not allowed to access any member of any class
C. A function which is allowed to access public and protected members of a class
D. A function which is allowed to access only public members of a class
A. 10
B. 0
C. No Output
D. Compilation Error
A. Yes, always.
B. No, never.
C. Only if the derived class explicitly declares the base class as a friend.
D. Only if the derived class is declared as a friend within the base class.
Whether you're a beginner to learn the fundamentals or an experienced developer looking to brush up on your skills, our MCQs on C++ offer an interactive way to test your understanding of concepts.
C++ is the most common and important programming language. The programming language was invented by Bjarne Stroustrup in 1979. The main purpose of designing C++ is for system programming to increase performance, efficiency, and flexibility. C++ supports procedural, object-oriented, game development, and generic programming which makes this programming language versatile for various applications. One of the main key features of C++ is it is rich in libraries. C++ also supports the low level of memory manipulation which becomes very important for developing operating systems and game engines.
When a class is defined without an object, no memory is allocated to it. Once an object of the class is created, memory will be allocated.
In C++, access specifiers are keywords that define the accessibility of members (attributes and methods) of a class. There are three primary access specifiers:
Variables are the identifiers that showcase data storage locations in computer memory. Variables can be defined based on scope, storage duration, and linkage.
The main advantages of C++ MCQs questions are as follows:
We hope this collection of C++ Multiple Choice Questions has been a valuable resource in your learning journey. Keep practicing and exploring C++ mcq questions and answers to solidify your understanding.