Most 100 C++ Language Interview Question & Answer | CodeBaaj |


C++ Interview Questions & Answers (Top 100)

Basics of C++

  1. What is C++?
    C++ is an object-oriented programming language developed by Bjarne Stroustrup as an extension of C.
  2. Is C++ a compiled language?
    Yes, C++ is a compiled language.
  3. Who developed C++?
    Bjarne Stroustrup.
  4. What is OOP?
    OOP (Object-Oriented Programming) is a programming paradigm based on objects and classes.
  5. What are the main features of C++?
    OOP, portability, performance, memory management, STL.
  6. What is a class?
    A class is a blueprint for creating objects.
  7. What is an object?
    An object is an instance of a class.
  8. What is namespace?
    Namespace is used to avoid name conflicts in large programs.
  9. What is std?
    std is the standard namespace in C++.
  10. What is main() function?
    It is the entry point of a C++ program.

Data Types & Variables

  1. What are primitive data types in C++?
    int, float, double, char, bool.
  2. What is sizeof() operator?
    It returns the size of a data type in bytes.
  3. Difference between float and double?
    double has more precision than float.
  4. What is a constant?
    A variable whose value cannot be changed.
  5. How to declare a constant?
    Using const keyword.

Operators

  1. What are operators?
    Symbols used to perform operations.
  2. Types of operators in C++?
    Arithmetic, Relational, Logical, Assignment, Bitwise.
  3. What is ternary operator?
    condition ? true : false
  4. What is increment operator?
    Increases value by 1 (++).
  5. Difference between ++i and i++?
    ++i increments first, i++ increments later.

Control Statements

  1. What is if statement?
    Executes code if condition is true.
  2. What is switch statement?
    Selects execution paths based on value.
  3. Difference between for and while loop?
    for is entry-controlled, while checks condition first.
  4. What is do-while loop?
    Executes at least once.
  5. What is break?
    Terminates loop or switch.

Functions

  1. What is a function?
    A block of code that performs a task.
  2. What is function overloading?
    Same function name with different parameters.
  3. What is recursion?
    Function calling itself.
  4. What is inline function?
    Expands function code at compile time.
  5. What is default argument?
    A predefined value for function parameter.

Arrays & Strings

  1. What is an array?
    Collection of same data type elements.
  2. What is a string in C++?
    Sequence of characters.
  3. Difference between array and vector?
    Vector is dynamic, array is static.
  4. What is strlen()?
    Returns string length.
  5. What is multidimensional array?
    Array with more than one dimension.

Pointers & References

  1. What is a pointer?
    Variable that stores address of another variable.
  2. What is NULL pointer?
    Pointer that points to nothing.
  3. What is reference variable?
    Alias of another variable.
  4. Difference between pointer and reference?
    Pointer can be null, reference cannot.
  5. What is dangling pointer?
    Pointer pointing to deleted memory.

OOP Concepts

  1. What is encapsulation?
    Binding data and functions together.
  2. What is inheritance?
    Acquiring properties of another class.
  3. What is polymorphism?
    Same function behaves differently.
  4. What is abstraction?
    Hiding implementation details.
  5. Types of inheritance?
    Single, Multiple, Multilevel, Hierarchical, Hybrid.

Constructors & Destructors

  1. What is constructor?
    Special function called when object is created.
  2. What is destructor?
    Called when object is destroyed.
  3. Types of constructors?
    Default, Parameterized, Copy.
  4. What is copy constructor?
    Initializes object using another object.
  5. Can constructor be virtual?
    No.

Virtual Functions

  1. What is virtual function?
    Function overridden in derived class.
  2. What is runtime polymorphism?
    Achieved using virtual functions.
  3. What is virtual keyword?
    Enables dynamic binding.
  4. What is base class?
    Parent class.
  5. What is derived class?
    Child class.

Memory Management

  1. What is new keyword?
    Allocates memory dynamically.
  2. What is delete keyword?
    Frees allocated memory.
  3. What is memory leak?
    Memory not released after use.
  4. Stack vs Heap?
    Stack is automatic, Heap is dynamic.
  5. What is dynamic memory allocation?
    Allocating memory at runtime.

File Handling

  1. What is file handling?
    Reading/writing data to files.
  2. File handling classes?
    ifstream, ofstream, fstream.
  3. What is ifstream?
    Reads from file.
  4. What is ofstream?
    Writes to file.
  5. What is fstream?
    Reads and writes.

STL (Standard Template Library)

  1. What is STL?
    Collection of templates.
  2. Components of STL?
    Containers, Algorithms, Iterators.
  3. What is vector?
    Dynamic array.
  4. What is map?
    Stores key-value pairs.
  5. What is iterator?
    Used to traverse containers.

Exception Handling

  1. What is exception?
    Runtime error.
  2. Keywords for exception handling?
    try, catch, throw.
  3. What is try block?
    Code that may cause exception.
  4. What is catch block?
    Handles exception.
  5. What is throw?
    Throws exception manually.

Miscellaneous

  1. What is header file?
    Contains declarations.
  2. Difference between C and C++?
    C is procedural, C++ is OOP.
  3. What is template?
    Generic programming feature.
  4. What is typedef?
    Creates alias for data types.
  5. What is mutable keyword?
    Allows modification in const object.

Advanced Concepts

  1. What is const function?
    Cannot modify object.
  2. What is friend function?
    Access private members.
  3. What is static variable?
    Retains value between calls.
  4. What is volatile keyword?
    Prevents optimization.
  5. What is this pointer?
    Points to current object.

Interview Practical Questions

  1. Can main() be overloaded?
    No.
  2. Can we have multiple inheritance?
    Yes.
  3. Can destructor be virtual?
    Yes.
  4. What is pure virtual function?
    Virtual function with =0.
  5. What is abstract class?
    Class with pure virtual function.

Final Set

  1. What is operator overloading?
    Redefining operators.
  2. What is inline namespace?
    Namespace treated as parent.
  3. What is smart pointer?
    Automatically manages memory.
  4. Types of smart pointers?
    unique_ptr, shared_ptr, weak_ptr.
  5. What is lambda function?
    Anonymous function.
  6. What is constexpr?
    Compile-time constant.
  7. What is auto keyword?
    Automatic type deduction.
  8. What is nullptr?
    Type-safe null pointer.
  9. What is range-based for loop?
    Loop for containers.
  10. Why C++ is fast?
    Close to hardware, compiled, manual memory control.

Leave a Reply

Your email address will not be published. Required fields are marked *