Q1. What is a function in C++?
A function is a reusable block of code designed to perform a specific task. It helps in modular programming, reduces redundancy, and improves readability of code.
Q2. What are the parts of a function?
- Return Type
- Function Name
- Parameters (Optional)
- Function Body
Q3. What is function declaration?
Function declaration (prototype) tells the compiler about the functionโs name, return type, and parameters before its actual definition.
Q4. What is function definition?
Function definition contains the actual implementation of the function logic.
Q5. What is function calling?
Calling a function means executing the function by using its name followed by parentheses.
Q6. What is pass by value?
In pass by value, a copy of the variable is passed to the function. Changes inside the function do not affect the original variable.
Q7. What is pass by reference?
In pass by reference, the actual memory address is passed. Changes inside the function affect the original variable.
Q8. What is default argument?
Default arguments allow parameters to have predefined values if no value is passed during function call.
Q9. What is function overloading?
Function overloading allows multiple functions with the same name but different parameters in the same scope.
Q10. What is inline function?
An inline function is expanded at the place where it is called, reducing function call overhead.
Q11. What is a class in C++?
A class is a user-defined data type that contains data members and member functions. It is the blueprint for creating objects.
Q12. What is an object?
An object is an instance of a class that contains actual values and can access class methods.
Q13. What are access specifiers?
- Private โ Accessible only inside the class
- Public โ Accessible outside the class
- Protected โ Accessible in derived classes
Q14. What is a constructor?
A constructor is a special member function that initializes objects. It has the same name as the class.
Q15. What is a destructor?
A destructor is used to release resources when an object goes out of scope.
Q16. What is encapsulation?
Encapsulation is wrapping data and functions into a single unit (class) and restricting direct access using access specifiers.
Q17. What is inheritance?
Inheritance allows one class to acquire properties and methods of another class.
Q18. What is polymorphism?
Polymorphism allows the same function name to behave differently in different situations (compile-time and runtime).
Q19. What is abstraction?
Abstraction hides internal implementation and shows only essential features.
Q20. What is virtual function?
A virtual function ensures that the derived class function is called at runtime (runtime polymorphism).
Q21. What is an error in C++?
An error is a problem that prevents the program from compiling or running correctly.
Q22. Types of errors in C++?
- Syntax Errors
- Runtime Errors
- Logical Errors
Q23. What is exception handling?
Exception handling is a mechanism to handle runtime errors using try, catch, and throw keywords.
Q24. What is try block?
Code that may cause an exception is placed inside the try block.
Q25. What is catch block?
The catch block handles the exception thrown from try block.
Q26. What is throw keyword?
The throw keyword is used to generate an exception.
Q27. What is stack unwinding?
Stack unwinding is the process of cleaning up function calls when an exception occurs.
4. Data Structures in C++
Q28. What is a data structure?
A data structure is a way of organizing and storing data efficiently.
Q29. What is an array?
An array is a collection of elements of the same data type stored in contiguous memory locations.
Q30. What is a vector?
A vector is a dynamic array provided by STL that can resize automatically.
Q31. What is a linked list?
A linked list is a linear data structure where elements are stored in nodes connected via pointers.
Q32. What is a stack?
A stack follows LIFO (Last In First Out) principle.
Q33. What is a queue?
A queue follows FIFO (First In First Out) principle.
Q34. What is a map?
A map stores elements in key-value pairs with unique keys.
Q35. What is a set?
A set stores unique elements in sorted order.
Q36. What is a namespace?
A namespace is a container used to organize code and prevent name conflicts.
Q37. Why is namespace std used?
The std namespace contains standard library components like cout, cin, string, vector, etc.
Q38. What is using namespace std?
It allows direct use of standard library names without prefixing std::
Q39. Can we create custom namespaces?
Yes, programmers can define their own namespaces to organize large projects.
Q40. What is nested namespace?
A namespace declared inside another namespace is called nested namespace.
Q41. Difference between struct and class?
In struct, members are public by default. In class, members are private by default.
Q42. What is pointer?
A pointer stores the address of another variable.
Q43. What is dynamic memory allocation?
Memory allocation at runtime using new and delete operators.
Q44. What is STL?
Standard Template Library provides containers, iterators, and algorithms.
Q45. What is template in C++?
Templates allow writing generic and reusable code.
Q46. What is const keyword?
Const is used to define variables whose value cannot be changed.
Q47. What is friend function?
A friend function can access private members of a class.
Q48. What is operator overloading?
Operator overloading allows redefining the meaning of operators for user-defined types.
Q49. What is copy constructor?
A constructor used to create a new object as a copy of an existing object.
Q50. What is difference between C and C++?
C is procedural programming language, while C++ supports object-oriented programming along with procedural features.
๐ข Join Our WhatsApp Channel
๐ผ Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.
๐ Join WhatsApp Now๐ข Join Our Telegram Channel
๐ผ Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!
๐ Join Telegram