Subjectnest.com
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools
Menu
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools

Marketing MCQs

SEO MCQs

Social Media Marketing MCQs

Content Marketing MCQs

Digital Marketing MCQs

Pay-Per-Click (PPC) MCQs

Email Marketing MCQs

Mobile Marketing MCQs

Online Marketing MCQs

YouTube Marketing MCQs

Conversion Rate Optimization MCQs

Exam Preparation MCQs

MDCAT Support & Movement MCQs

MDCAT Alcohols and Phenols MCQs

MDCAT Dawn of Modern Physics MCQs

CSS English MCQs

CSS Business Administration MCQs

CSS Anthropology MCQs

Nts Multiple Choice

MDCAT Variation & Genetics MCQs

MDCAT Aldehydes and Ketones MCQs

MDCAT Spectra MCQs

CSS Pakistan Affairs MCQs

CSS Town Planning & Urban Management MCQs

CSS Pashto MCQs

NTS English Preparation Mcqs

MDCAT Fundamentals of Chemistry MCQs

MDCAT Acids MCQs

MDACT Nuclear Physics MCQs

CSS Current Affairs MCQs

CSS Computer Science MCQs

CSS Persian MCQs

NTS Physics Preparation Mcqs

MDCAT Gases MCQs

MDCAT Molecules MCQs

PPSC General Knowledge MCQs

CSS Islamic Studies MCQs

CSS International Relations MCQs

CSS Punjabi MCQs

MDCAT IMPORTANT MCQs

MDCAT Liquid MCQs

PPSC Solved MCQs Part 1

PPSC Current Affairs MCQs

CSS Comparative Study MCQs

CSS Political Science MCQs

CSS Constitutional Law MCQs

MDCAT Kingdom Animalia MCQs

MDCAT Solid MCQs

MDCAT Force and Motion MCQs

PPSC Pakistan Studies MCQs

CSS Geology MCQs

CSS Gender Studies MCQs

CSS International Law MCQs

Nervous & Chemical Coordination MCQs

MDCAT Chemical Equilibrium MCQs

MDCAT Work and Energy MCQs

PPSC Islamic Studies MCQs

CSS Statistics MCQs

CSS Environmental Science MCQs

CSS Muslim Law & Jurisprudence MCQs

MDCAT Cell Structure & Function MCQs

MDCAT Thermochemistry MCQs

MDCAT Rotational and Circular Motion MCQs

PPSC Geography MCQs

CSS History of Pakistan and India MCQs

CSS Agriculture and Forestry MCQs

CSS Mercantile Law MCQs

MDCAT Biological Molecules (Biomolecules) MCQs

MDCAT Electrochemistry MCQs

MDCAT Waves MCQs

PPSC English MCQs

CSS Accountancy & Auditing MCQs

CSS Botany MCQs

CSS Criminology MCQs

MDCAT Bioenergetics MCQs

MDCAT English MCQs

MDCAT Thermodynamics MCQs

PPSC Urdu MCQs

CSS Economics MCQs

CSS Zoology MCQs

CSS Philosophy MCQs

MDCAT Biodiversity (Variety of Life ) MCQs

MDCAT Chemical Bonding MCQs

MDCAT Electrostatics MCQs

PPSC Everyday Science MCQs

CSS Islamic History & Culture MCQs

CSS English Literature MCQs

CSS Arabic MCQs

MDCAT Enzymes MCQs

MDCAT S and P Block Elements MCQs

MDCAT Current Electricity MCQs

PPSC Computer MCQs

CSS British History MCQs

CSS Law MCQs

MDCAT Evolution MCQs

MDACT Transition Elements MCQs

MDCAT Electromagnetism MCQs

PPSC Mathematics MCQs

CSS European History MCQs

CSS Journalism & Mass Communication MCQs

MDCAT Nutrition & Gaseous Exchange MCQs

MDCAT Organic Chemistry MCQs

MDCAT Electromagnetic Induction MCQs

CSS Physics MCQs

CSS History of the USA MCQs

CSS Psychology MCQs

MDCAT Prokaryotes MCQs

MDCAT Hydrocarbons MCQs

MDCAT Electronics MCQs

CSS Chemistry MCQs

CSS Public Administration MCQs

CSS Geography MCQs

C++ Multiple-Choice

This comprehensive set of MCQs on C++ is designed to cover all essential topics necessary for mastering the principles and practices of this powerful programming language. Focused on key subjects such as object-oriented programming, data types, control structures, functions, and standard libraries, these MCQs aim to help students and professionals build a strong foundation in C++, which is widely used in software development, game programming, and systems design.

Who should practice C++ MCQs?

• Students pursuing degrees in computer science, software engineering, or information technology who need to understand the fundamentals of C++.
• Individuals preparing for exams or certifications that include C++ programming as part of their curriculum.
• Anyone aiming to strengthen their coding skills and proficiency in object-oriented programming concepts.
• Candidates looking to improve their problem-solving abilities and algorithmic thinking using C++.
• Professionals seeking to enhance their programming skills and explore advanced features of C++ for practical applications.
• Suitable for all students eager to develop their technical skills and gain confidence in using C++ for various programming challenges.

 

 1. Which of the following is the correct syntax for a C++ comment?

A. // Comment
B. /* Comment */
C. Both A and B
D. None of the above

View Answer
C

 

2. What is the size of an int data type in C++?

A. 2 bytes
B. 4 bytes
C. 8 bytes
D. Depends on the system/compiler

View Answer
D

 

3. Which of the following is used to define a constant in C++?

A. #define
B. const
C. Both A and B
D. None of the above

View Answer
C

 

4. Which of the following is not a valid C++ identifier?

A. variable_1
B. _variable
C. 1_variable
D. variable1

View Answer
C

 

5. Which keyword is used to declare a class in C++?

A. struct
B. class
C. object
D. typedef

View Answer
B

 

6. What is the correct syntax for a for loop in C++?

A. for (initialization; condition; increment)
B. for (condition; initialization; increment)
C. for (initialization; increment; condition)
D. for (increment; condition; initialization)

View Answer
A

 

7. Which function is used to read a single character from the user in C++?

A. getchar()
B. get()
C. cin.get()
D. scanf()

View Answer
C

 

8. What will be the output of the following code?

#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10;
cout << a + b << endl;
return 0;
}

A. 5
B. 10
C. 15
D. 20

View Answer
C

 

9. Which of the following is used to allocate memory dynamically in C++?

A. malloc
B. alloc
C. new
D. create

View Answer
C

 

10. What is the default return type of the main function in C++?

A. void
B. int
C. float
D. char

View Answer
B

 

11. Which of the following operators cannot be overloaded in C++?

A. +
B. =
C. >
D. ::

View Answer
D

 

12. What is the output of the following code?

#include <iostream>
using namespace std;
void foo(int &a) {
a = a + 10;
}
int main() {
int x = 5;
foo(x);
cout << x << endl;
return 0;
}

A. 5
B. 10
C. 15
D. 20

View Answer
C

 

13. Which header file is needed to use the std::vector class?

A. <vector>
B. <list>
C. <map>
D. <queue>

View Answer
A

 

14. Which function is used to find the length of a string in C++?

A. strlen()
B. length()
C. size()
D. Both B and C

View Answer
D

 

15. Which of the following is not a fundamental data type in C++?

A. int
B. float
C. string
D. double

View Answer
C

 

16. What is the output of the following code?

#include <iostream>
using namespace std;
int main() {
int a = 10, b = 20;
cout << (a > b ? a : b) << endl;
return 0;
}

A. 10
B. 20
C. 30
D. None of the above

View Answer
B

 

17. Which of the following is a valid function prototype in C++?

A. int func();
B. int func(int a);
C. void func(double a, int b);
D. All of the above

View Answer
D

 

18. Which of the following is the correct syntax for a destructor in C++?

A. ~ClassName()
B. ClassName()
C. #ClassName()
D. *ClassName()

View Answer
A

 

19. What is the correct way to declare a constant pointer to an integer in C++?

A. int* const ptr;
B. const int* ptr;
C. const int* const ptr;
D. int const* ptr;

View Answer
A

 

20. Which of the following access specifiers is used as default in a class in C++?

A. public
B. private
C. protected
D. friend

View Answer
B

 

21. Which of the following statements is true about inline functions in C++?

A. They improve performance by eliminating function call overhead.
B. They increase the size of the binary file.
C. They can be defined inside the class definition.
D. All of the above

View Answer
D

 

22. Which of the following keywords is used to inherit a class in C++?

A. inherits
B. extends
C. implements
D. :

View Answer
D

 

23. What is the correct syntax to declare a friend function in C++?

A. friend return_type function_name();
B. friend function_name();
C. return_type friend function_name();
D. friend return_type function_name;

View Answer
A

 

24. Which of the following is not a valid type of inheritance in C++?

A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

View Answer
D

 

25. What is the output of the following code?

#include <iostream>
using namespace std;
class Base {
public:
virtual void show() {
cout << "Base class" << endl;
}
};
class Derived : public Base {
public:
void show() {
cout << "Derived class" << endl;
}
};
int main() {
Base* b;
Derived d;
b = &d;
b->show();
return 0;
}

A. Base class
B. Derived class
C. Compiletime error
D. Runtime error

View Answer
B

 

26. Which of the following is true about virtual functions in C++?

A. They can be overridden in derived classes.
B. They must be declared in the base class.
C. They ensure dynamic binding.
D. All of the above

View Answer
D

 

27. Which of the following operators is used to access members of a structure through a pointer in C++?

A. .
B. >
C. *
D. &

View Answer
B

 

28. What is the output of the following code?

#include <iostream>
using namespace std;
void func(int a, int b = 20) {
cout << a << " " << b << endl;
}
int main() {
func(10);
return 0;
}

A. 10 20
B. 10 0
C. 10 10
D. Compiletime error

View Answer
A

 

29. Which of the following is used to terminate a loop in C++?

A. break
B. exit
C. return
D. All of the above

View Answer
A

 

30. Which of the following is not a member of the iostream library in C++?

A. cin
B. cout
C. cerr
D. printf

View Answer
D

 

31. Which of the following is not a standard exception class in C++?
A. std::bad_alloc
B. std::out_of_range
C. std::bad_exception
D. std::not_found

View Answer
D

 

32. Which of the following functions is used to generate random numbers in C++?
A. random()
B. srand()
C. rand()
D. generate_random()

View Answer
C

 

33. What is the output of the following code?

#include <iostream>
using namespace std;
class Test {
public:
Test() {
cout << "Constructor called" << endl;
}
~Test() {
cout << "Destructor called" << endl;
}
};
int main() {
Test t;
return 0;
}

A. Constructor called
B. Destructor called
C. Constructor called Destructor called
D. Runtime error

View Answer
C

 

34. Which of the following is the correct way to create an array of 10 integers in C++?

A. int arr[10];
B. int arr = new int[10];
C. int arr[] = new int[10];
D. int arr[10] = {0};

View Answer
A

 

35. Which of the following statements is true about C++ arrays?

A. The size of the array must be determined at compile time.
B. The size of the array can be determined at runtime.
C. The size of the array can be changed dynamically.
D. Arrays can store elements of different types.

View Answer
A

 

36. What will be the output of the following code?

#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 20, 30, 40, 50};
cout << arr[2] << endl;
return 0;
}

A. 10
B. 20
C. 30
D. 40

View Answer
C

 

37. Which of the following is not a storage class in C++?

A. auto
B. register
C. static
D. local

View Answer
D

 

38. What is the purpose of the friend keyword in C++?

A. To declare a class as a friend of another class
B. To allow a function or class to access private or protected members of another class
C. To create a new data type
D. To create a global variable

View Answer
B

 

39. Which of the following is the correct syntax for a switch statement in C++?

A. switch (expression) { case value1: statement; break; }
B. switch { case value1: statement; break; }
C. switch (expression) { value1: statement; break; }
D. switch (value1) { case: statement; break; }

View Answer
A

 

40. What is the output of the following code?

#include <iostream>
using namespace std;
int main() {
int a = 10;
int* p = &a;
cout << *p << endl;
return 0;
}

A. 10
B. Address of a
C. Compiletime error
D. Runtime error

View Answer
A

 

41. Which of the following best describes encapsulation in OOP?

A. Combining data and methods into a single unit
B. Deriving a new class from an existing class
C. Hiding implementation details from the user
D. Using a common interface for multiple implementations

View Answer
A

 

42. What is polymorphism in OOP?

A. The ability to create multiple classes from a base class
B. The ability to process objects differently based on their data type or class
C. The ability to bind data and methods into a single unit
D. The ability to hide implementation details from the user

View Answer
B

 

43. Which of the following is not a principle of OOP?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Compilation

View Answer
D

 

44. What is inheritance in OOP?

A. The ability to create multiple classes from a base class
B. The ability to process objects differently based on their data type or class
C. The ability to bind data and methods into a single unit
D. The ability to hide implementation details from the user

View Answer
A

 

45. Which keyword is used to inherit a class in C++?

A. inherits
B. extends
C. :
D. implements

View Answer
C

 

46. Which of the following is true about abstract classes in C++?

A. They cannot be instantiated.
B. They can have both pure virtual functions and nonpure virtual functions.
C. They are intended to be base classes.
D. All of the above

View Answer
D

 

47. What is the purpose of a constructor in a class?

A. To initialize the object of the class
B. To destroy the object of the class
C. To allocate memory for the object
D. To define the interface of the class

View Answer
A

 

48. Which of the following is true about destructors in C++?

A. They are automatically called when an object is destroyed.
B. They can be overloaded.
C. They can have parameters.
D. They must be explicitly called.

View Answer
A

 

49. What is the output of the following code?

#include <iostream>
using namespace std;
class Base {
public:
virtual void display() {
cout << "Base class" << endl;
}
};
class Derived : public Base {
public:
void display() {
cout << "Derived class" << endl;
}
};
int main() {
Base* b;
Derived d;
b = &d;
b->display();
return 0;
}

A. Base class
B. Derived class
C. Compiletime error
D. Runtime error

View Answer
B

 

50. Which of the following is used to achieve runtime polymorphism in C++?

A. Function overloading
B. Operator overloading
C. Virtual functions
D. Inline functions

View Answer
C

 

51. Which of the following is not a type of inheritance in OOP?

A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hierarchical inheritance

View Answer
D

 

52. Which of the following is an example of function overloading?

A. Two functions with the same name but different parameters
B. Two functions with different names but same parameters
C. Two functions with the same name and same parameters
D. Two functions with different return types

View Answer
A

 

53. What is the main purpose of operator overloading in C++?

A. To provide new implementations for existing operators
B. To allow operators to be used with userdefined data types
C. To increase the performance of operators
D. To create new operators

View Answer
B

 

54. Which of the following best describes a pure virtual function in C++?

A. A function with no implementation in the base class
B. A function that can be overridden in derived classes
C. A function that must be implemented in derived classes
D. Both A and C

View Answer
D

 

55. Which of the following is not a characteristic of an abstract class in C++?

A. It cannot be instantiated.
B. It can have constructors.
C. It can have pure virtual functions.
D. It can have only pure virtual functions.

View Answer
D

 

56. What is the output of the following code?

#include <iostream>
using namespace std;
class Base {
public:
virtual void show() {
cout << "Base" << endl;
}
};
class Derived : public Base {
public:
void show() {
cout << "Derived" << endl;
}
};
int main() {
Base* b = new Derived();
b->show();
delete b;
return 0;
}

A. Base
B. Derived
C. Compiletime error
D. Runtime error

View Answer
B

 
57. What is the purpose of the this pointer in C++?

A. To refer to the current object
B. To refer to the base class
C. To refer to the derived class
D. To refer to a global object

View Answer
A

 

58. Which of the following best describes inheritance in OOP?

A. It allows a class to use the properties and methods of another class.
B. It allows a class to hide its implementation details.
C. It allows a class to implement multiple interfaces.
D. It allows a class to override methods of another class.

View Answer
A

 

59. Which of the following best describes encapsulation in OOP?

A. It allows a class to use the properties and methods of another class.
B. It allows a class to hide its implementation details.
C. It allows a class to implement multiple interfaces.
D. It allows a class to override methods of another class.

View Answer
B

 

60. Which of the following is not a type of polymorphism in OOP?

A. Compiletime polymorphism
B. Runtime polymorphism
C. Virtual polymorphism
D. Both A and B

View Answer
C

 

61. What is the purpose of a virtual destructor in C++?

A. To prevent memory leaks when deleting a base class pointer pointing to a derived class object
B. To allow the destructor to be overridden in derived classes
C. To improve performance of destructors
D. To provide a default destructor implementation

View Answer
A

 

62. Which of the following is true about multiple inheritance in C++?

A. A class can inherit from multiple classes.
B. A class can only inherit from one class.
C. Multiple inheritance is not supported in C++.
D. Multiple inheritance is supported but not recommended.

View Answer
A

 

63. What is the output of the following code?

#include <iostream>
using namespace std;
class A {
public:
void show() {
cout << "Class A" << endl;
}
};
class B : public A {
public:
void show() {
cout << "Class B" << endl;
}
};
int main() {
B obj;
obj.show();
return 0;
}

A. Class A
B. Class B
C. Compiletime error
D. Runtime error

View Answer
B

 

64. Which of the following is not a benefit of using OOP?

A. Reusability
B. Scalability
C. Security
D. Speed

View Answer
D

 

65. What is the output of the following code?

#include <iostream>
using namespace std;
class Base {
public:
virtual void display() = 0;
};
class Derived : public Base {
public:
void display() {
cout << "Derived class" << endl;
}
};
int main() {
Derived d;
d.display();
return 0;
}

A. Base class
B. Derived class
C. Compiletime error
D. Runtime error

View Answer
B

 

66. Which of the following is not a feature of OOP?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Concurrency

View Answer
D

 

67. Which of the following is true about constructors in C++?

A. They can be overloaded.
B. They are automatically called when an object is created.
C. They cannot be virtual.
D. All of the above

View Answer
D

 

68. Which of the following is true about destructors in C++?

A. They are automatically called when an object is destroyed.
B. They can be overloaded.
C. They can have parameters.
D. They must be explicitly called.

View Answer
A

 

69. Which of the following best describes a pure virtual function in C++?

A. A function with no implementation in the base class
B. A function that can be overridden in derived classes
C. A function that must be implemented in derived classes
D. Both A and C

View Answer
D

 

70. What is the output of the following code?

#include <iostream>
using namespace std;
class A {
public:
virtual void show() = 0;
};
class B : public A {
public:
void show() {
cout << "Class B" << endl;
}
};
int main() {
A* a = new B();
a->show();
delete a;
return 0;
}

A. Class A
B. Class B
C. Compiletime error
D. Runtime error

View Answer
B

 

71. Which of the following is true about abstract classes in C++?

A. They cannot be instantiated.
B. They can have both pure virtual functions and nonpure virtual functions.
C. They are intended to be base classes.
D. All of the above

View Answer
D

 

72. Which of the following is not a type of inheritance in C++?

A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

View Answer
D

 

73. Which of the following best describes polymorphism in OOP?

A. The ability to create multiple classes from a base class
B. The ability to process objects differently based on their data type or class
C. The ability to bind data and methods into a single unit
D. The ability to hide implementation details from the user

View Answer
B

 

74. Which of the following is not a principle of OOP?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Compilation

View Answer
D

 

75. Which of the following is true about virtual functions in C++?

A. They can be overridden in derived classes.
B. They must be declared in the base class.
C. They ensure dynamic binding.
D. All of the above

View Answer
D

 

76. What is the purpose of the this pointer in C++?

A. To refer to the current object
B. To refer to the base class
C. To refer to the derived class
D. To refer to a global object

View Answer
A

 

77. Which of the following is true about inheritance in OOP?

A. It allows a class to use the properties and methods of another class.
B. It allows a class to hide its implementation details.
C. It allows a class to implement multiple interfaces.
D. It allows a class to override methods of another class.

View Answer
A

 

78. Which of the following is true about encapsulation in OOP?

A. It allows a class to use the properties and methods of another class.
B. It allows a class to hide its implementation details.
C. It allows a class to implement multiple interfaces.
D. It allows a class to override methods of another class.

View Answer
B

 

79. Which of the following is not a type of polymorphism in OOP?

A. Compiletime polymorphism
B. Runtime polymorphism
C. Virtual polymorphism
D. Both A and B

View Answer
C

 

80. What is the purpose of a virtual destructor in C++?

A. To prevent memory leaks when deleting a base class pointer pointing to a derived class object
B. To allow the destructor to be overridden in derived classes
C. To improve performance of destructors
D. To provide a default destructor implementation

View Answer
A

 

Facebook
WhatsApp
LinkedIn

All Subject MCQs

Current Affairs MCQs

Fine Arts MCQs

Physiotherapy MCQs

Microsoft Azure MCQs

General Knowledge MCQs

Islamic Studies MCQs

Jammu and Kashmir Studies MCQs

English Basic MCQ

Machine Design MCQs

Physical Education MCQs

Nursing MCQs

Report writing MCQs

WEB ONTOLOGY MCQs

Geography MCQs

UDC and LDC Clerk MCQs

Physics Basic MCQs

E-COMMERCE MCQs

Management Sciences MCQs

Land Records MCQs

Chemistry MCQs

HTML MCQS

Pedagogy MCQs

Terrorism in Pakistan MCQs

Leadership MCQs

Cascading Style Sheets (CSS) MCQS

Psychology MCQs

Engineering MCQs

PHP MCQS

Botany MCQs

Biology MCQs

Artificial Intelligence (AI) MCQs

Zoology MCQs

Math MCQs

Data Science MCQs

Agriculture MCQs

Statistics MCQs

C++ Multiple-Choice

Current Affairs MCQs

Economics MCQs

Data Structures MCQs

Everyday Science MCQs

Philosophy MCQs

Operating System MCQs

Pakistan Studies MCQs

Political Science MCQs

UNIX Operating System MCQs

Environmental MCQs

Ethics MCQs

DISCRETE MATHEMATICS MCQS

Library science MCQs

Social Studies MCQs

Computer Basic MCQs

Dental MCQs

Computer Science MCQs

Automata Theory MCQs

Digital Image Processing MCQs

Artificial Intelligence (AI) MCQs

Mobile Android Applications Mcqs

Mobile android applications MCQs

Data Science MCQs

Multimedia System MCQs

Graph Algorithms MCQs

C++ Multiple-Choice

Real-Time Systems MCQs

CAD MCQs

Data Structures MCQs

C Programming Mcqs

Embedded System MCQs

Operating System MCQs

Computer Basic MCQs

Web Security and forensics MCQs

UNIX Operating System MCQs

OOP MCQs

Python MCQs

Digital Logic Design MCQs

LINUX Operating System MCQs

Microsoft Office MCQs

Database System MCQs

Data Mining MCQs

Internet and Email MCQs

Compiler Construction MCQs

Software Architecture MCQs

Computer general knowledge MCQs

Computer Architecture MCQs

Software Formal Methods MCQs

Social Networks MCQs

Software Requirement Engineering MCQs

Software Project Management MCQs

Graphic designing MCQs

Software Testing MCQs

Object-Oriented Analysis And Design MCQs

Photoshop MCQs

Software quality Assurance MCQs

UML MCQs

Corel Draw MCQs

Software Fault Tolerance MCQS

Computer Graphics MCQs

Parallel and Distributed Computing MCQs

Software Risk Management MCQS

Network MCQs

  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools
Menu
  • Home
  • About
  • Contact
  • Privacy Policy
    • Terms of Use
    • Cookie Privacy Policy
    • California Consumer Privacy Act (CCPA)
    • DMCA
  • Free Tools

© 2024 All rights Reserved. Design by Arslan

Powered by Subject Nest