C++ Q&A
- Home
- / Python Handay
- / C++ Q&A
- What is C++?
A high-level programming language that supports object-oriented, procedural, and generic programming. - What are the main features of C++?
Object-oriented programming, inheritance, polymorphism, encapsulation, templates, and operator overloading. - What is the difference between C and C++?
C is a procedural language; C++ supports both procedural and object-oriented programming. - What are the types of comments in C++?
Single-line (//) and multi-line (/* … */) comments. - What is a header file?
A file containing C++ declarations and macro definitions, typically included at the beginning of a program. - What is a class?
A blueprint for creating objects that encapsulate data and methods. - What is an object?
An instance of a class containing both data and methods. - What is inheritance?
A mechanism where one class derives properties and behavior from another class. - What is polymorphism?
The ability to present the same interface for different underlying forms (data types). - What is encapsulation?
The bundling of data and methods that operate on the data within a single unit (class) - What are built-in data types in C++?
int, char, float, double, and bool. - What is a reference variable?
An alias for another variable, allowing indirect access to its value. - What is the difference between struct and class?
Members of struct are public by default; members of class are private by default. - What is a pointer?
A variable that stores the memory address of another variable. - What is dynamic memory allocation?
The process of allocating memory at runtime using operators like new and delete. - What is the difference between for, while, and do-while loops?
for loops are used for a known number of iterations; while checks the condition before execution; do-while executes at least once. - What is a switch statement?
A control statement that executes a block of code based on the value of an expression. - What is a function in C++?
A block of code that performs a specific task and can return a value. - What is function overloading?
Defining multiple functions with the same name but different parameters. - What is function overriding?
Redefining a function in a derived class that already exists in the base class. - What is the inline keyword?
A suggestion to the compiler to insert the function’s body directly into the calling code to reduce function call overhead. - What is recursion?
A technique where a function calls itself to solve a problem. - What is an exception?
An event that disrupts the normal flow of a program, typically due to errors. - What is the purpose of try and catch?
To handle exceptions gracefully without crashing the program. - What is the throw keyword?
Used to signal the occurrence of an exception. - What is a destructor?
A special member function that is called when an object goes out of scope or is deleted. - What is a try-catch-finally block?
A structure used to handle exceptions, with optional cleanup code in the finally block. - What are templates in C++?
A feature that allows writing generic functions and classes that work with any data type. - What is the Standard Template Library (STL)?
A powerful library that provides a set of common classes and functions for data structures and algorithms. - What is a vector?
A dynamic array provided by STL that can resize itself automatically. - What is a list?
A doubly-linked list provided by STL that allows non-contiguous memory allocation. - What is a map?
An associative container that stores key-value pairs with unique keys. - What is operator overloading?
The ability to redefine the meaning of operators for user-defined types. - What are friend functions?
Functions declared with the friend keyword that can access private and protected members of a class. - What is a copy constructor?
A constructor that initializes an object using another object of the same class. - What is a memory leak?
A situation where memory is allocated but not properly deallocated, leading to increased memory usage. - What is the stack and heap?
Stack is used for static memory allocation; heap is used for dynamic memory allocation. - What is the new operator?
Used to allocate memory for an object or array dynamically. - What is the delete operator?
Used to deallocate memory allocated with new. - What is file handling in C++?
The process of reading from and writing to files using streams. - What is binary file handling?
Reading from and writing to files in binary format, which allows for non-text data storage. - What is multithreading?
The ability to execute multiple threads concurrently within a single process. - What is a thread?
A lightweight process that can run independently. - What is a virtual function?
A function declared in a base class that can be overridden in derived classes to achieve polymorphism. - What is a pure virtual function?
A virtual function with no implementation in the base class, making the class abstract. - What is multiple inheritance?
A feature that allows a class to inherit from more than one base class. - What are namespaces?
A way to organize code and prevent name conflicts by grouping related identifiers. - What are inline functions?
Functions defined with the inline keyword to reduce function call overhead. - What is template specialization?
The ability to define different implementations of a template for specific data types. - What is the sizeof operator?
An operator that returns the size (in bytes) of a data type or object. - What are enumerations?
A user-defined data type that consists of integral constants, improving code readability. - What is the significance of main() function?
The entry point for any C++ program. - What are static members?
Members that belong to the class rather than any instance, shared across all instances. - What is nullptr?
A keyword representing a null pointer in C++11 and beyond.