Home
Education
D/L Mode
HTML CSS JavaScript Python SQL Node.js PHP Java C++

Welcome to C++

Start your journey in high performance programming

Lessons

Start learning step by step

Question & Answer

Check your understanding

Interview Asked Questions

Prepare for real interviews

Quiz

Test your skills

πŸ’» C++ Lesson 1: Introduction to C++

C++ is a powerful, high-performance programming language used for system programming, game development, and competitive programming.

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, C++!" << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 2: Variables and Data Types

Variables store data. C++ has several data types like int, float, double, char, and string.

#include <iostream>
using namespace std;

int main() {
    int age = 25;
    float height = 5.9;
    char grade = 'A';
    string name = "Zohil";

    cout << "Name: " << name << endl;
    cout << "Age: " << age << ", Height: " << height << endl;
    cout << "Grade: " << grade << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 3: Operators

C++ has arithmetic, relational, logical, and assignment operators.

#include <iostream>
using namespace std;

int main() {
    int a = 10, b = 5;

    // Arithmetic
    cout << "a + b = " << a + b << endl;
    cout << "a - b = " << a - b << endl;

    // Relational
    cout << "a > b? " << (a > b) << endl;

    // Logical
    cout << "(a > 0 && b > 0)? " << (a > 0 && b > 0) << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 4: Input & Output

Use cin to take input and cout to display output.

#include <iostream>
using namespace std;

int main() {
    string name;
    int age;

    cout << "Enter your name: ";
    cin >> name;

    cout << "Enter your age: ";
    cin >> age;

    cout << "Hello " << name << ", you are " << age << " years old." << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 5: Conditional Statements

Use if, else if, and else to make decisions in your code.

#include <iostream>
using namespace std;

int main() {
    int marks;
    cout << "Enter marks: ";
    cin >> marks;

    if(marks >= 90) {
        cout << "Grade A" << endl;
    } else if(marks >= 75) {
        cout << "Grade B" << endl;
    } else if(marks >= 50) {
        cout << "Grade C" << endl;
    } else {
        cout << "Fail" << endl;
    }

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 6: Loops - for, while, do-while

Loops allow repeating code multiple times.

#include <iostream>
using namespace std;

int main() {
    cout << "For loop: " << endl;
    for(int i=1; i<=5; i++) {
        cout << i << " ";
    }
    cout << endl;

    cout << "While loop: " << endl;
    int j = 1;
    while(j <= 5) {
        cout << j << " ";
        j++;
    }
    cout << endl;

    cout << "Do-while loop: " << endl;
    int k = 1;
    do {
        cout << k << " ";
        k++;
    } while(k <= 5);

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 7: Functions

Functions allow you to reuse code and organize programs.

#include <iostream>
using namespace std;

// Function to add two numbers
int add(int a, int b) {
    return a + b;
}

int main() {
    int result = add(5, 3);
    cout << "5 + 3 = " << result << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 8: Arrays

Arrays store multiple values of the same type in a single variable.

#include <iostream>
using namespace std;

int main() {
    int numbers[5] = {10, 20, 30, 40, 50};

    cout << "Array elements: ";
    for(int i=0; i<5; i++) {
        cout << numbers[i] << " ";
    }
    cout << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 9: Strings

C++ string class allows working with text easily.

#include <iostream>
#include <string>
using namespace std;

int main() {
    string name = "Zohil";
    cout << "Name: " << name << endl;

    cout << "Length: " << name.length() << endl;
    cout << "Uppercase first char: " << char(toupper(name[0])) << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 10: Conditional & Ternary Operator

The ternary operator is a shortcut for if-else.

#include <iostream>
using namespace std;

int main() {
    int age;
    cout << "Enter age: ";
    cin >> age;

    string result = (age >= 18) ? "Adult" : "Minor";
    cout << "You are: " << result << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 11: Pointers

Pointers store the memory address of variables and allow direct memory manipulation.

#include <iostream>
using namespace std;

int main() {
    int num = 42;
    int* ptr = # // pointer to num

    cout << "Value: " << num << endl;
    cout << "Address: " << ptr << endl;
    cout << "Value via pointer: " << *ptr << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 12: References

References are aliases for variables, often used for function arguments to avoid copying.

#include <iostream>
using namespace std;

void addOne(int &ref) {
    ref += 1; // modifies original variable
}

int main() {
    int num = 10;
    addOne(num);
    cout << "After addOne: " << num << endl; // 11
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 13: Dynamic Memory Allocation

Use new and delete to allocate memory at runtime.

#include <iostream>
using namespace std;

int main() {
    int* ptr = new int; // dynamically allocate integer
    *ptr = 100;
    cout << "Value: " << *ptr << endl;
    delete ptr; // free memory

    int n;
    cout << "Enter array size: ";
    cin >> n;
    int* arr = new int[n]; // dynamic array

    for(int i=0; i<n; i++) arr[i] = i+1;
    for(int i=0; i<n; i++) cout << arr[i] << " ";
    cout << endl;

    delete[] arr; // free array memory
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 14: Multidimensional Arrays

Store data in rows and columns using 2D arrays.

#include <iostream>
using namespace std;

int main() {
    int matrix[2][3] = {{1,2,3},{4,5,6}};

    for(int i=0; i<2; i++) {
        for(int j=0; j<3; j++) {
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 15: Strings & Character Arrays

C++ supports string class and C-style character arrays.

#include <iostream>
#include <string>
using namespace std;

int main() {
    string name = "Zohil";
    char greeting[] = "Hello";

    cout << "String: " << name << endl;
    cout << "Char array: " << greeting << endl;

    cout << "Length of string: " << name.length() << endl;
    cout << "Length of char array: " << sizeof(greeting)/sizeof(greeting[0]) << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 16: Classes & Objects

Classes are blueprints for objects. Objects are instances of classes.

#include <iostream>
using namespace std;

class Student {
public:
    string name;
    int age;
};

int main() {
    Student s1;
    s1.name = "Zohil";
    s1.age = 20;

    cout << "Name: " << s1.name << ", Age: " << s1.age << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 17: Member Functions

Functions inside a class are called member functions and can operate on class data.

#include <iostream>
using namespace std;

class Student {
public:
    string name;
    int age;

    void display() {
        cout << "Name: " << name << ", Age: " << age << endl;
    }
};

int main() {
    Student s1;
    s1.name = "Zohil";
    s1.age = 20;
    s1.display();
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 18: Constructors

Constructors are special functions called when an object is created to initialize data.

#include <iostream>
using namespace std;

class Student {
public:
    string name;
    int age;

    // Constructor
    Student(string n, int a) {
        name = n;
        age = a;
    }

    void display() {
        cout << "Name: " << name << ", Age: " << age << endl;
    }
};

int main() {
    Student s1("Zohil", 20);
    s1.display();
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 19: Destructors

Destructors are special functions called when an object is destroyed to release resources.

#include <iostream>
using namespace std;

class Student {
public:
    string name;

    Student(string n) { name = n; cout << "Constructor called for " << name << endl; }
    ~Student() { cout << "Destructor called for " << name << endl; }
};

int main() {
    Student s1("Zohil");
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 20: Access Specifiers

Access specifiers control access to class members: public, private, and protected.

#include <iostream>
using namespace std;

class Student {
private:
    string name;
public:
    void setName(string n) { name = n; }
    void display() { cout << "Name: " << name << endl; }
};

int main() {
    Student s1;
    s1.setName("Zohil");
    s1.display();
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 21: Inheritance

Inheritance allows a class to acquire properties and methods of another class.

#include <iostream>
using namespace std;

// Base class
class Person {
public:
    string name;
    void greet() { cout << "Hello, " << name << endl; }
};

// Derived class
class Student : public Person {
public:
    int rollNo;
};

int main() {
    Student s;
    s.name = "Zohil";
    s.rollNo = 101;
    s.greet();
    cout << "Roll No: " << s.rollNo << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 22: Polymorphism (Function Overloading)

Polymorphism allows methods with the same name to behave differently based on parameters.

#include <iostream>
using namespace std;

class Math {
public:
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
};

int main() {
    Math m;
    cout << "Int sum: " << m.add(5, 3) << endl;
    cout << "Double sum: " << m.add(5.5, 3.2) << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 23: Operator Overloading

Operator overloading allows customizing the behavior of operators for user-defined types.

#include <iostream>
using namespace std;

class Point {
public:
    int x, y;
    Point(int a, int b) { x = a; y = b; }

    // Overload + operator
    Point operator+ (Point p) {
        return Point(x + p.x, y + p.y);
    }
};

int main() {
    Point p1(1,2), p2(3,4);
    Point p3 = p1 + p2;
    cout << "p3: (" << p3.x << "," << p3.y << ")" << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 24: Encapsulation

Encapsulation hides internal data of a class and allows controlled access using getters and setters.

#include <iostream>
using namespace std;

class Student {
private:
    int age;
public:
    void setAge(int a) {
        if(a >= 0) age = a;
        else cout << "Invalid age!" << endl;
    }
    int getAge() { return age; }
};

int main() {
    Student s;
    s.setAge(20);
    cout << "Age: " << s.getAge() << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 25: Static Members

Static members belong to the class, not objects, and share the same value across all objects.

#include <iostream>
using namespace std;

class Student {
public:
    static int count;
    Student() { count++; }
};

int Student::count = 0;

int main() {
    Student s1, s2;
    cout << "Total students: " << Student::count << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 26: File Handling - Reading & Writing

C++ allows reading from and writing to files using fstream, ifstream, and ofstream.

#include <iostream>
#include <fstream>
using namespace std;

int main() {
    // Writing to a file
    ofstream outFile("example.txt");
    outFile << "Hello C++ File!" << endl;
    outFile.close();

    // Reading from a file
    ifstream inFile("example.txt");
    string line;
    while(getline(inFile, line)) {
        cout << line << endl;
    }
    inFile.close();

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 27: Function Templates

Templates allow writing generic functions that work with any data type.

#include <iostream>
using namespace std;

template <typename T>
T add(T a, T b) {
    return a + b;
}

int main() {
    cout << "Int sum: " << add(5, 3) << endl;
    cout << "Double sum: " << add(5.5, 3.2) << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 28: Exception Handling

Exceptions allow handling runtime errors gracefully using try, catch, and throw.

#include <iostream>
using namespace std;

int main() {
    int a = 10, b;
    cout << "Enter divisor: ";
    cin >> b;

    try {
        if(b == 0) throw "Division by zero!";
        cout << "Result: " << a/b << endl;
    } catch(const char* e) {
        cout << "Error: " << e << endl;
    }

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 29: STL Basics - Containers

The Standard Template Library (STL) provides ready-to-use containers like vector, list, map, etc.

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> nums = {1, 2, 3, 4, 5};

    cout << "Vector elements: ";
    for(int n : nums) {
        cout << n << " ";
    }
    cout << endl;

    cout << "Size: " << nums.size() << endl;
    return 0;
}
    
βœ”

πŸ’» C++ Lesson 30: Vectors

Vectors are dynamic arrays in C++ STL that can grow or shrink at runtime.

#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> nums;

    // Add elements
    nums.push_back(10);
    nums.push_back(20);
    nums.push_back(30);

    // Access elements
    cout << "First element: " << nums[0] << endl;

    // Remove last element
    nums.pop_back();

    cout << "Vector elements: ";
    for(int n : nums) cout << n << " ";
    cout << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 31: STL Map

Maps store key-value pairs with unique keys and provide fast lookup.

#include <iostream>
#include <map>
using namespace std;

int main() {
    map<string, int> scores;
    scores["Zohil"] = 95;
    scores["Ali"] = 88;

    cout << "Zohil's score: " << scores["Zohil"] << endl;

    for(auto &pair : scores) {
        cout << pair.first << ": " << pair.second << endl;
    }

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 32: STL Set

Sets store unique elements in sorted order.

#include <iostream>
#include <set>
using namespace std;

int main() {
    set<int> numbers = {5, 1, 3, 3, 2};

    cout << "Set elements: ";
    for(int n : numbers) cout << n << " ";
    cout << endl;

    numbers.insert(4);
    numbers.erase(1);

    cout << "Updated set: ";
    for(int n : numbers) cout << n << " ";
    cout << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 33: STL Queue

Queue is a First-In-First-Out (FIFO) container in STL.

#include <iostream>
#include <queue>
using namespace std;

int main() {
    queue<int> q;

    q.push(10);
    q.push(20);
    q.push(30);

    cout << "Front: " << q.front() << ", Back: " << q.back() << endl;

    q.pop(); // remove front

    cout << "After pop, Front: " << q.front() << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 34: STL Stack

Stack is a Last-In-First-Out (LIFO) container in STL.

#include <iostream>
#include <stack>
using namespace std;

int main() {
    stack<int> s;

    s.push(10);
    s.push(20);
    s.push(30);

    cout << "Top element: " << s.top() << endl;

    s.pop(); // remove top

    cout << "After pop, Top: " << s.top() << endl;

    return 0;
}
    
βœ”

πŸ’» C++ Lesson 35: Final Project Idea - Student Management System

Combine everything you learned to build a simple project.

// Features:
// - Add, Display, Update, Delete Students
// - Store Name, Age, Roll No
// - Use Classes, Vectors, Functions, File I/O

#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Student {
public:
    string name;
    int age;
    int rollNo;
};

int main() {
    vector<Student> students;

    // Example: add a student
    Student s1;
    s1.name = "Zohil";
    s1.age = 20;
    s1.rollNo = 101;
    students.push_back(s1);

    // Display all students
    for(auto &s : students) {
        cout << s.name << ", Age: " << s.age << ", Roll No: " << s.rollNo << endl;
    }

    return 0;
}
    
πŸŽ‰ Congratulations! You have completed all C++ lessons!
Keep practicing and building amazing Applications!
βœ”

πŸ’‘C++ Questions & Answers

❓ What is C++?
C++ is a high-level, general-purpose programming language that supports procedural, object-oriented, and generic programming. It is an extension of C with classes and additional features for complex software development.
❓ What are the key features of C++?
Key features include object-oriented programming (OOP), classes and objects, inheritance, polymorphism, encapsulation, abstraction, operator overloading, templates for generic programming, and support for both low-level and high-level programming.
❓ What is the difference between C and C++?
C is a procedural programming language, while C++ supports both procedural and object-oriented programming. C++ includes features like classes, objects, inheritance, polymorphism, templates, and exception handling, which are not present in C.
❓ What are the differences between `struct` and `class` in C++?
- `struct`: Members are public by default.
- `class`: Members are private by default.
Both can have member functions, constructors, destructors, and support inheritance, but `class` is commonly used for encapsulation and OOP design.
❓ What is the difference between `new` and `malloc()` in C++?
`new` is an operator in C++ that allocates memory and calls the constructor of an object, returning a typed pointer.
`malloc()` is a C library function that allocates memory but does not call constructors and returns a void pointer that requires casting.
❓ What is a constructor and destructor in C++?
A constructor is a special member function called automatically when an object is created; it initializes object data.
A destructor is a special member function called automatically when an object is destroyed; it cleans up resources used by the object.
❓ What is the difference between `public`, `private`, and `protected` access specifiers?
- `public`: Members are accessible from anywhere.
- `private`: Members are accessible only within the class.
- `protected`: Members are accessible within the class and derived classes.
❓ What is inheritance in C++?
Inheritance allows a class (derived class) to acquire properties and behaviors of another class (base class). It promotes code reuse and supports hierarchical class structures.
❓ What are the different types of inheritance in C++?
C++ supports:
- Single inheritance: One base class
- Multiple inheritance: More than one base class
- Multilevel inheritance: Chain of inheritance
- Hierarchical inheritance: Multiple derived classes from a single base class
- Hybrid inheritance: Combination of above types
❓ What is polymorphism in C++?
Polymorphism allows objects to take many forms.
- Compile-time (Static) polymorphism: Achieved via function overloading and operator overloading.
- Run-time (Dynamic) polymorphism: Achieved via virtual functions and inheritance.
❓ What is the difference between `function overloading` and `function overriding` in C++?
- Function overloading: Same function name with different parameter lists in the same scope (compile-time polymorphism).
- Function overriding: Derived class provides a new implementation for a base class function with the same signature (runtime polymorphism).
❓ What is a virtual function in C++?
A virtual function is a member function in a base class declared with the `virtual` keyword. It allows derived classes to override it so that the appropriate function is called at runtime (dynamic binding).
❓ What is the difference between a pointer and a reference in C++?
- Pointer: Holds the memory address of a variable, can be reassigned, can be null.
- Reference: An alias for an existing variable, must be initialized during declaration, cannot be null, cannot be reassigned.
❓ What is the difference between stack and heap memory in C++?
- Stack: Stores local variables and function calls, memory is automatically managed, fast access, limited size.
- Heap: Stores dynamically allocated memory using `new` or `malloc()`, memory must be manually managed, slower access, larger size.
❓ What are templates in C++?
Templates allow writing generic functions or classes that work with any data type. They provide type safety and eliminate code duplication by allowing functions/classes to operate on different types without rewriting code.
❓ What is the difference between `deep copy` and `shallow copy` in C++?
- Shallow copy: Copies only the pointer values, so both objects point to the same memory. Changes in one object affect the other.
- Deep copy: Copies the actual data and allocates separate memory. Changes in one object do not affect the other.
❓ What is the difference between `delete` and `delete[]` in C++?
- `delete`: Frees memory allocated for a single object created using `new`.
- `delete[]`: Frees memory allocated for an array of objects created using `new[]`.
❓ What is exception handling in C++?
Exception handling is a mechanism to handle runtime errors using `try`, `catch`, and `throw` blocks. It prevents program termination and allows graceful recovery from errors.
❓ What is the difference between `struct` and `union` in C++?
- `struct`: All members have their own memory; size equals sum of members.
- `union`: All members share the same memory; size equals the largest member. Only one member can hold a value at a time.
❓ What is the difference between `const` and `constexpr` in C++?
- `const`: Value cannot be changed after initialization; can be evaluated at runtime or compile-time.
- `constexpr`: Value is evaluated at compile-time and guarantees constant expression; improves performance and allows compile-time calculations.
❓ What is the difference between `inline` function and macro in C++?
- Inline function: Defined using the `inline` keyword; evaluated by the compiler; type-safe; supports debugging.
- Macro: Preprocessor directive `#define`; simple text replacement; no type safety; harder to debug.
❓ What are smart pointers in C++?
Smart pointers are template classes that manage dynamically allocated memory automatically, preventing memory leaks. Types include `unique_ptr`, `shared_ptr`, and `weak_ptr`.
❓ What is the difference between `std::vector` and `std::list`?
- `std::vector`: Dynamic array, fast random access, slow insertions/deletions in the middle.
- `std::list`: Doubly linked list, fast insertions/deletions anywhere, slower random access.
❓ What is RAII in C++?
RAII (Resource Acquisition Is Initialization) is a programming idiom where resource allocation is tied to object lifetime. Resources are acquired in constructors and released in destructors, ensuring automatic cleanup.
❓ What is the difference between `throw()` and `noexcept` in C++?
- `throw()`: Exception specification in older C++ versions, indicates function does not throw exceptions.
- `noexcept`: Modern C++ keyword; guarantees function will not throw exceptions; allows compiler optimizations.
❓ What is the difference between `friend` function and member function in C++?
- Member function: Defined inside a class and can access private/protected members directly.
- Friend function: Defined outside the class but declared with `friend` keyword; can access private/protected members but is not part of the class.
❓ What is the difference between `static` and `dynamic` binding in C++?
- Static binding: Function call resolved at compile-time (e.g., normal member functions).
- Dynamic binding: Function call resolved at runtime using virtual functions; enables runtime polymorphism.
❓ What is the difference between `stack` and `queue` in C++?
- Stack: LIFO (Last-In-First-Out) data structure; supports `push()` and `pop()`.
- Queue: FIFO (First-In-First-Out) data structure; supports `enqueue()` and `dequeue()`. C++ provides `std::stack` and `std::queue` in STL.
❓ What are the different types of cast operators in C++?
C++ supports:
- `static_cast`: Compile-time type conversion.
- `dynamic_cast`: Runtime checked cast (used with polymorphic classes).
- `const_cast`: Removes or adds `const` qualifier.
- `reinterpret_cast`: Low-level reinterpretation of bit patterns (dangerous if misused).
❓ What is the difference between `std::map` and `std::unordered_map`?
- `std::map`: Ordered associative container implemented as a balanced binary tree; keys are stored in sorted order; slower lookup.
- `std::unordered_map`: Hash table based; keys are not ordered; faster average lookup, insertion, and deletion.

🎯 C++ Interview Questions

❓ What is C++?
C++ is a high-level, general-purpose programming language that supports procedural, object-oriented, and generic programming. It is an extension of C with classes and additional features for complex software development.
❓ What are the key features of C++?
Key features include object-oriented programming (OOP), classes and objects, inheritance, polymorphism, encapsulation, abstraction, operator overloading, templates for generic programming, and support for both low-level and high-level programming.
❓ What is the difference between C and C++?
C is a procedural programming language, while C++ supports both procedural and object-oriented programming. C++ includes features like classes, objects, inheritance, polymorphism, templates, and exception handling, which are not present in C.
❓ What are constructors and destructors in C++?
A constructor is a special member function called automatically when an object is created; it initializes object data. A destructor is called automatically when an object is destroyed and is used to free resources.
❓ What is inheritance in C++?
Inheritance allows a class (derived class) to acquire properties and behaviors of another class (base class). It promotes code reuse and supports hierarchical class structures.
❓ What is polymorphism in C++?
Polymorphism allows objects to take many forms. Compile-time polymorphism is achieved via function and operator overloading, while run-time polymorphism is achieved via virtual functions.
❓ What is the difference between `struct` and `class`?
In C++, `struct` members are public by default, while `class` members are private by default. Both can have functions, constructors, destructors, and support inheritance.
❓ What is the difference between `new` and `malloc()`?
`new` allocates memory and calls the constructor, returning a typed pointer. `malloc()` allocates memory but does not call the constructor and returns a void pointer requiring casting.
❓ What are templates in C++?
Templates allow writing generic functions or classes that work with any data type. They provide type safety and reduce code duplication by allowing functions/classes to operate on multiple types without rewriting code.
❓ What is exception handling in C++?
Exception handling allows runtime errors to be managed using `try`, `catch`, and `throw` blocks. It prevents program termination and allows graceful error recovery.

πŸ“ C++ Quiz: Test Your Knowledge

1. C++ is an extension of which programming language?

2. Which of the following is used to define a class in C++?

3. Which function is the entry point of a C++ program?

4. Which operator is used for scope resolution in C++?

5. Which of the following is a correct comment in C++?

6. Which of these is the correct way to declare a pointer in C++?

7. Which access specifier makes class members accessible only within the class?

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

9. What is the correct way to define a constructor in C++?

10. Which operator is used for bitwise AND in C++?

11. Which of the following is a loop that executes at least once?

12. Which of the following is not a C++ access specifier?

13. Which of the following is used to include a library in C++?

14. Which keyword is used to define a constant in C++?

×