{"id":22379300,"url":"https://github.com/ahadalireach/oop.interview.questions","last_synced_at":"2026-03-06T23:32:28.193Z","repository":{"id":275021909,"uuid":"915218590","full_name":"ahadalireach/oop.interview.questions","owner":"ahadalireach","description":"A repository containing fundamentals of programming, OOP, and other related concepts with interview questions and code implementations.","archived":false,"fork":false,"pushed_at":"2025-03-16T13:51:50.000Z","size":560,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T02:21:27.927Z","etag":null,"topics":["cpp","exceptions","interview-questions","oop","oop-concepts","oop-principles","pointers","strings","templates"],"latest_commit_sha":null,"homepage":"https://github.com/ahadalireach/oop.concepts.interview.questions","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahadalireach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-11T09:20:55.000Z","updated_at":"2025-07-14T20:15:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"10634eb5-1ee1-4148-85d6-00c17bfa9b01","html_url":"https://github.com/ahadalireach/oop.interview.questions","commit_stats":null,"previous_names":["ahadalireach/cpp.concepts.iq","ahadalireach/oop.concepts.interview.questions","ahadalireach/oop.interview.questions","ahadalireach/cpp.interview.questions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahadalireach/oop.interview.questions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahadalireach%2Foop.interview.questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahadalireach%2Foop.interview.questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahadalireach%2Foop.interview.questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahadalireach%2Foop.interview.questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahadalireach","download_url":"https://codeload.github.com/ahadalireach/oop.interview.questions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahadalireach%2Foop.interview.questions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30203351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","exceptions","interview-questions","oop","oop-concepts","oop-principles","pointers","strings","templates"],"created_at":"2024-12-04T23:09:31.243Z","updated_at":"2026-03-06T23:32:28.168Z","avatar_url":"https://github.com/ahadalireach.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ Concepts with Interview Questions\n\n\u003ca id=\"table-of-contents\"\u003e\u003c/a\u003e\n\n| No. | Questions |\n| --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| 001. | [What is Programming, and Why is C++ a Preferred Language?](#what-is-programming-and-why-is-c-a-preferred-language) |\n| 002. | [What is a Programming Paradigm, and Why is it Important?](#what-is-a-programming-paradigm-and-why-is-it-important) |\n| 003. | [How Does C++ Differ from C?](#how-does-c-differ-from-c) |\n| 004. | [What is the File Structure in a C++ Program?](#what-is-the-file-structure-in-a-c-program) |\n| 005. | [What is the Difference Between Low-Level and High-Level Programming Languages?](#what-is-the-difference-between-low-level-and-high-level-programming-languages) |\n| 006. | [What are Variables and Comments, and Why are They Used?](#what-are-variables-and-comments-and-why-are-they-used) |\n| 007. | [What is Variable Scope, and How Does it Affect Code Execution?](#what-is-variable-scope-and-how-does-it-affect-code-execution) |\n| 008. | [What are Data Types in C++, and How Are They Classified?](#what-are-data-types-in-c-and-how-are-they-classified) |\n| 009. | [What Are Reserved Keywords in C++, and Why Are They Restricted?](#what-are-reserved-keywords-in-c-and-why-are-they-restricted) |\n| 010. | [What are Operators and Their Different Types?](#what-are-operators-and-their-different-types) |\n| 011. | [What is the Difference Between `float`, `double`, and `long double` Literals?](#what-is-the-difference-between-float-double-and-long-double-literals) |\n| 012. | [What is Typecasting?](#what-is-typecasting) |\n| 013. | [How Do You Use the Scope Resolution Operator?](#how-do-you-use-the-scope-resolution-operator) |\n| 014. | [What are Constants, Manipulators, and Operator Precedence?](#what-are-constants-manipulators-and-operator-precedence) |\n| 015. | [What are Control Structures?](#what-are-control-structures) |\n| 016. | [What is the Differences Between For, While, and Do-While Loops?](#what-is-the-differences-between-for-while-and-do-while-loops) |\n| 017. | [What is the Difference Between Break and Continue Statements?](#what-is-the-difference-between-break-and-continue-statements) |\n| 018. | [What is a Pointer and How is it Used?](#what-is-a-pointer-and-how-is-it-used) |\n| 019. | [What is the concept of Null Pointer?](#what-is-a-null-pointer) |\n| 020. | [What is the concept of Garbage Collection](#garbage-collection-in-c) |\n| 021. | [What is an Array, and How are Arrays and Pointers Related?](#what-is-an-array-and-how-are-arrays-and-pointers-related-in-c) |\n| 022. | [What are Struct, Union, and Enums in C++?](#what-are-struct-union-and-enums-in-c) |\n| 023. | [What are Function and Function Prototypes?](#what-are-function-and-function-prototypes) |\n| 024. | [What are Actual and Formal Parameters?](#what-are-actual-and-formal-parameters) |\n| 025. | [What does it means by Call by Value, Call by Reference, \u0026 Call by Pointer?](#call-by-value-call-by-reference-call-by-pointer) |\n| 026. | [What are Static Variables \u0026 Functions?](#what-are-static-variable--functions) |\n| 027. | [What are Inline Functions, Default Arguments, \u0026 Constant Arguments?](#inline-functions-default-arguments-constant-arguments) |\n| 028. | [What is Recursion and Recursive Functions?](#recursion-and-recursive-functions) |\n| 029. | [What is Function Overloading?](#what-is-function-overloading) |\n| 030. | [What is OOP?](#what-is-oop) |\n| 031. | [Why OOP? Purpose of Implementing OOP?](#why-oop-purpose-of-implementing-oop) |\n| 032. | [Why is OOP so Popular?](#why-is-oop-so-popular) |\n| 033. | [What are the Pros and Cons of Object-Oriented Programming (OOP)?](#pros-and-cons-of-object-oriented-programming-oop) |\n| 034. | [What is the Difference Between Object-Oriented Programming vs Structural Programming?](#difference-between-object-oriented-programming-vs-structural-programming) |\n| 035. | [What is the Difference Between Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP)?](#difference-between-procedure-oriented-programming-pop-and-object-oriented-programming-oop) |\n| 036. | [What is a Pure Object-Oriented Language?](#what-is-a-pure-object-oriented-language) |\n| 037. | [What is a Struct?](#what-is-a-struct) |\n| 038. | [What is a Class and Why Do We Need It in OOP?](#what-is-a-class-and-why-do-we-need-it-in-oop) |\n| 039. | [What are Class Attributes \u0026 Methods in OOP?](#what-are-class-attributes-and-methods-in-oop) |\n| 040. | [Why Use a Class Instead of a Struct?](#why-use-a-class-instead-of-a-struct) |\n| 041. | [What is the Difference Between Class and Struct?](#difference-between-class-and-struct) |\n| 042. | [What are the Similarities Between Class and Struct?](#similarities-between-class-and-struct) |\n| 043. | [What is an Object and Why Do We Need It in OOP?](#what-is-an-object-and-why-do-we-need-it-in-oop) |\n| 044. | [What is an Array of Objects?](#what-is-an-array-of-objects) |\n| 045. | [How do you Pass Objects as Function Arguments?](#how-do-you-pass-objects-as-function-arguments) |\n| 046. | [What is Pointer to Objects in C++? What are its Purpose and Benefits?](#pointer-to-objects-in-c-purpose-and-benefits) |\n| 047. | [How is Memory Allocated for Variables, Functions, Member Functions, and Data Members?](#how-is-memory-allocation-for-variables-functions-member-functions-and-data-members) |\n| 048. | [What are Access Specifiers in OOP?](#what-are-access-specifiers-in-oop) |\n| 049. | [What is the Default Access Modifier in a Class?](#what-is-the-default-access-modifier-in-a-class) |\n| 050. | [What is Sealed Modifier?](#what-is-the-sealed-modifier) |\n| 051. | [## What is Dynamic Memory Allocation (DMA) and the new Keyword? What are Their Purpose and Benefits?](#what-is-dynamic-memory-allocation-dma-and-the-new-keyword-in-c-purpose-and-benefits) |\n| 052. | [What is the `delete` Keyword? What are its Purpose and Benefits?](#what-is-the-delete-keyword-in-c-purpose-and-benefits) |\n| 053. | [What is the Arrow (`-\u003e`) and Dot (`.`) Operator? What is its Purpose or Benefit?](#what-is-the-arrow--and-dot--operator-in-c) |\n| 054. | [What Happens When an Object is Created Without `new` vs With `new`? Where is it stored?](#what-happens-when-an-object-is-created-without-new-vs-with-new-where-is-it-stored) |\n| 055. | [What is Shallow Copy? and What’s the Problem with Shallow Copy?](#what-is-shallow-copy-and-whats-the-problem-with-shallow-copy) |\n| 056. | [What is Deep Copy?](#what-is-deep-copy) |\n| 057. | [What is the Difference Between Shallow and Deep Copy of a Class?](#what-is-the-difference-between-shallow-and-deep-copy-of-a-class) |\n| 058. | [Explain the Concept of static in OOP, Including Static Data Members and Static Member Functions?](#explain-the-concept-of-static-in-oop-including-static-data-members-and-static-member-functions) |\n| 059. | [How many Types of Variables are there in OOP?](#types-of-variables-in-oop) |\n| 060. | [What is `const` in OOP and How is it Used?](#what-is-const-in-oop-and-how-is-it-used) |\n| 061. | [What are Friend Functions and Friend Classes?](#what-are-friend-functions-and-friend-classes) |\n| 062. | [What are Member Functions \u0026 Nesting of Member Functions in OOP?](#what-are-member-functions-and-nesting-of-member-functions-in-oop) |\n| 063. | [What is `this` pointer in OOP and its purpose?](what-is-the-purpose-of-this-pointer-in-oop) |\n| 064. |[What is a constructor, and what are its rules and types?](#what-is-a-constructor-and-what-are-its-rules-and-types) |\n| 065. |[What is the Difference Between Constructor vs Method?](#difference-between-constructor-vs-method) |\n| 066. |[Is it possible to overload a constructor? What is constructor overloading, what are its benefits, and what are its conditions or rules?](#is-it-possible-to-overload-a-constructor-what-is-constructor-overloading-what-are-its-benefits-and-what-are-its-condition-or-rules) |\n| 067. |[What is a Copy Constructor: Is the Object Passed by Value or Reference, and Why?](#copy-constructor-is-the-object-passed-by-value-or-reference-and-why)|\n| 068. |[Where is a Copy Constructor Called Implicitly?](#where-is-a-copy-constructor-called-implicitly)|\n| 069. |[What is the Difference Between Copy Constructor vs Assignment Operator?](#difference-between-copy-constructor-vs-assignment-operator)|\n| 070. |[What Does It Mean by Constructors with Default Arguments?](#what-does-it-mean-by-constructors-with-default-arguments)|\n| 071. |[What is Dynamic Initialization of Objects Using Constructors?](#what-is-dynamic-initialization-of-objects-using-constructors)|\n| 072. |[What is Constructor Delegation?](#what-is-constructor-delegation)|\n| 073. |[What is a Constructor Initialization List, and Why Do We Use It?](#what-is-a-constructor-initialization-list-and-why-do-we-use-it)|\n| 074. |[Can a Constructor be Private or Protected?](#can-a-constructor-be-private-or-protected)|\n| 075. |[Can a Constructor be Static or Const? Why or Why Not?](#can-a-constructor-be-static-or-const-why-or-why-not)|\n| 076. |[Can We Make a Constructor Private? How Will We Create an Object of Such a Class?](#can-we-make-a-constructor-private-how-will-we-create-an-object-of-such-a-class)|\n| 077. |[What is a Destructor? When Do We Need to Define Destructors?](#what-is-a-destructor-when-do-we-need-to-define-destructors)|\n| 078. |[Is it Possible to Overload a Destructor?Is it Possible to Overload a Destructor? What is Destructor Overloading, Its Benefits, and Why Is It Not Possible?](#is-it-possible-to-overload-a-destructor-what-is-destructor-overloading-its-benefits-and-why-is-it-not-possible)|\n| 079. |[Why Does a Class Have Only One Destructor \u0026 Why Do We Need One?](#why-does-a-class-have-only-one-destructor-and-why-do-we-need-one)|\n| 080. |[Can a Destructor be Private or Protected?](#can-a-destructor-be-private-or-protected)|\n| 081. |[Can a Destructor be Static or Const?](#can-a-destructor-be-static-or-const)|\n| 082. |[What is the Order of Constructor and Destructor Calling Sequence?](#order-of-constructor-and-destructor-calling-sequence) |\n| 083. | [What is Encapsulation? Why is it important in software development? What are its key features?](#what-is-encapsulation-why-is-it-important-in-software-development-what-are-its-key-features) |\n| 084. | [What is the Concept of Setters and Getters? Why Do We Use Them? Provide a Code Example of Encapsulation.](#what-is-the-concept-of-setters-and-getters-and-why-do-we-use-them-provide-a-code-example-of-encapsulation) |\n| 085. | [How does Encapsulation promote modular code?](#how-does-encapsulation-promote-modular-code) |\n| 086. | [What challenges or pitfalls can you encounter when implementing Encapsulation?](#what-challenges-or-pitfalls-can-you-encounter-when-implementing-encapsulation)|\n| 087. | [What is Abstraction? Why is it important in software development? What are its key features?](#what-is-abstraction-why-is-it-important-in-software-development-what-are-its-key-features)|\n| 088. | [How does Abstraction differ from Encapsulation?](#how-does-abstraction-differ-from-encapsulation)|\n| 089. | [What is Inheritance? Explain Its Different Types.](#what-is-inheritance-explain-its-different-types)|\n| 090. | [What are Access Modifiers in Inheritance?](#what-are-access-modifiers-in-inheritance)|\n| 091. | [Can a subclass access private members of a superclass? Why or why not?](#can-a-subclass-access-private-members-of-a-superclass-why-or-why-not)|\n| 092. | [How does method overriding work in Inheritance?](#how-does-method-overriding-work-in-inheritance)|\n| 093. | [What is the difference between Method Overloading and Method Overriding?](#what-is-the-difference-between-method-overloading-and-method-overriding)|\n| 094. | [How does Inheritance affect performance?](#how-does-inheritance-affect-performance)|\n| 095. | [What happens if a constructor is not defined in a subclass?](#what-happens-if-a-constructor-is-not-defined-in-a-subclass)|\n| 096. | [What is Ambiguity in Inheritance? Explain How to Resolve It.](#what-is-ambiguity-in-inheritance-explain-how-to-resolve-it)|\n| 097. | [What is a Virtual Base Class in Inheritance and What Problem Does It Solve?](#what-is-a-virtual-base-class-in-inheritance-and-what-problem-does-it-solve)|\n| 098. | [What is the Diamond Problem and Its Solution?](#what-is-the-diamond-problem-and-its-solution)|\n| 099. | [What is Polymorphism? Why is it important in software development?](#what-is-polymorphism-why-is-it-important-in-software-development)|\n| 100. | [What are the Types of Polymorphism?](#what-are-the-types-of-polymorphism)|\n| 101. | [What is the Difference between Compile-time vs Run-time Polymorphism](#difference-between-compile-time-vs-run-time-polymorphism)|\n| 102. | [What is the Difference between Static Binding (Early Binding) vs Dynamic Binding (Late Binding)](#difference-between-static-binding-vs-dynamic-binding)|\n| 103. | [What is Function Overriding?](#what-is-function-overriding)|\n| 104. | [How does Polymorphism promote code reusability and flexibility?](#how-does-polymorphism-promote-code-reusability-and-flexibility)|\n| 105. | [What method makes classes exhibit different behavior in polymorphism?](#what-method-makes-classes-exhibit-different-behavior-in-polymorphism)|\n| 106. | [What is a Pointer to a Derived Class and Its Purpose?](#what-is-a-pointer-to-a-derived-class-and-its-purpose)|\n| 107. | [What is the Rule of Three?](#what-is-the-rule-of-three)|\n| 108. | [Can we override a static method? Why or why not?](#can-we-override-a-static-method-why-or-why-not)|\n| 109. | [What is a Virtual Function and Its Purpose?](#what-is-a-virtual-function-and-its-purpose) |\n| 110. | [What are the Rules for Virtual Functions?](#rules-for-virtual-functions) |\n| 111. | [Can Virtual Functions be Private?](#can-virtual-functions-be-private) |\n| 112. | [What are inline virtual functions? Are inline virtual functions really nonsense?](#what-are-inline-virtual-functions-are-inline-virtual-functions-really-nonsense) |\n| 113. | [What is a Pure Virtual Function, Its Purpose, and an Abstract Base Class?](#what-is-a-pure-virtual-function-and-its-purpose) |\n| 114. | [What is a Pure Abstract Base Class?](#what-is-a-pure-abstract-base-class) |\n| 115. | [Why Does a Pure Virtual Function Require a Function Body?](#why-does-a-pure-virtual-function-require-a-function-body) |\n| 116. | [What is the Difference between Virtual vs Pure Virtual Function?](#difference-between-virtual-vs-pure-virtual-function) |\n| 117. | [Can a Constructor be Virtual?](#can-a-constructor-be-virtual) |\n| 118. | [Can a Constructor be Pure Virtual?](#can-a-constructor-be-pure-virtual) |\n| 119. | [What is a Virtual Destructor?](#what-is-a-virtual-destructor) |\n| 120. | [What is a Pure Virtual Destructor?](#what-is-a-pure-virtual-destructor) |\n| 121. | [Can a Destructor be Virtual? Why and When to use virtual destructors?](#can-a-destructor-be-virtual) |\n| 122. | [Can a Destructor be Pure Virtual?](#can-a-destructor-be-pure-virtual) |\n| 123. | [Explain the concept of Message Passing.](#explain-the-concept-of-message-passing) |\n| 124. | [Explain the concept of a V-Table and what problem it solved?](#explain-the-concept-of-a-v-table-and-what-problem-it-solved) |\n| 125. | [What does it mean by Simulating a final class?](#simulating-a-final-class) |\n| 126. | [What is an Abstract Class? What is the major thing they don't allow us to do?](#what-is-an-abstract-class-what-is-the-major-thing-they-dont-allow-us-to-do) |\n| 127. | [What is the Difference between Abstract Class vs Normal Class vs Concrete Class?](#difference-between-abstract-class-vs-normal-class-vs-concrete-class) |\n| 128. | [What is an Interface?](#what-is-an-interface) |\n| 129. | [What is the Difference between Interface vs. Abstract Class?](#difference-between-interface-vs-abstract-class) |\n| 130.  | [Can you call the base class method without creating an instance?](#can-you-call-the-base-class-method-without-creating-instance) |\n| 131. | [Can an abstract class have implemented methods?](#can-an-abstract-class-have-implemented-methods) |\n| 132. | [What happens if we do not implement all methods of an interface in a class?](#what-happens-if-we-do-not-implement-all-methods-of-an-interface-in-a-class) |\n| 133. | [How to avoid the implementation of an abstract function?](#how-to-avoid-the-implementation-of-an-abstract-function) |\n| 134. | [How many instances can be created for an abstract class? Explain why.](#number-of-instances-for-an-abstract-class) |\n| 135. | [What is Operator Overloading? What main problem does it solve?](#what-is-operator-overloading-what-main-problem-does-it-solve) |\n| 136. | [What are templates? Explain the different types of templates with examples](#what-are-templates) |\n| 137. | [What Are Threads?](#what-are-threads) |\n| 138. | [What is an Exception?](#what-is-an-exception) |\n| 139. | [What is the Difference between Error vs Exception?](#difference-between-error-vs-exception) |\n| 140. | [What are Objects Relations?](#what-are-objects-relations) |\n| 141. | [What is Association?](#what-is-association) |\n| 142. | [What is Aggregation (Weak Relationship)?](#what-is-aggregation-weak-relationship) |\n| 143. | [What is Composition (Strong Relationship)?](#what-is-composition-strong-relationship) |\n| 144. | [What is a Has-a Relationship?](#what-is-a-has-a-relationship) |\n| 145. | [What is an Is-a Relationship?](#what-is-an-is-a-relationship) |\n| 146. | [What is the Difference between Is-a relationship and Has-a relationship (Aggregation vs. Composition)? Implement examples of each.](#is-a-relationship-vs-has-a-relationship-aggregation-vs-composition-implement-examples-of-each) |\n| 147. | [What is the Difference between Generalization, Aggregation, Composition and Association?](#generalization-vs-aggregation-vs-composition-vs-association) |\n| 148. | [Explain the concept of Coupling and Cohesion?](#explain-the-concept-of-coupling-and-cohesion) |\n| 149. | [Describe the Purpose, Importance, and Use of all the Keywords used in OOP, and what problem they solve:](#describe-the-purpose-importance-and-use-of-all-the-keywords-used-in-oop-and-what-problem-they-solve) |\n|      | [`Static`](#static) |\n|      | [`Virtual`](#virtual) |\n|      | [`Abstract`](#abstract) |\n|      | [`Final`](#final) |\n|      | [`Explicit`](#explicit) |\n|      | [`This`](#this) |\n|      | [`New`](#new) |\n|      | [`Const`](#const) |\n|      | [`Super`](#super) |\n|      | [`Override`](#override) |\n| 150. | [Why do we need all the OOP concepts?](#why-do-we-need-all-the-oop-concepts) |\n| 151. | [What problems do OOP concepts like Class, Object, Encapsulation, Abstraction, Inheritance, Polymorphism, and other related concepts solve?](#what-problems-do-oop-concepts-like-class-object-encapsulation-abstraction-inheritance-polymorphism-and-other-related-concepts-solve) |\n| 152. | [What problems arise without Static Binding, Dynamic Binding, Function Overloading, Function Overriding, and Inheritance? How do these concepts solve those problems and contribute to Object-Oriented Programming (OOP)?](#what-problems-arise-without-static-binding-dynamic-binding-function-overloading-function-overriding-and-inheritance-how-do-these-concepts-solve-those-problems-and-contribute-to-object-oriented-programming-oop) |\n| 153. | [Provide at least 3 Real-World Examples of OOP Concepts](#provide-at-least-3-real-world-examples-of-oop-concepts) |\n|      | [`Class`](#class) |\n|      | [`Object`](#object) |\n|      | [`Encapsulation`](#encapsulation) |\n|      | [`Abstraction`](#abstraction) |\n|      | [`Inheritance`](#inheritance) |\n|      | [`Polymorphism`](#polymorphism) |\n|      | [`Static vs Dynamic`](#static-vs-dynamic) |\n|      | [`Function Overloading`](#function-overloading) |\n|      | [`Function Overriding`](#function-overriding) |\n|      | [`Inheritance Types`](#inheritance-types) |\n| 154. | [How Do OOP Pillars Relate to Real-Life? (Self-Mapped Examples)](#how-do-oop-pillars-relate-to-real-life-self-mapped-examples) |\n\n\n## What is Programming, and Why is C++ a Preferred Language?\n\n**Programming**\n\nProgramming is the process of writing instructions for a computer to execute. These instructions, written in a programming language, enable the computer to perform specific tasks.\n\n**Why C++?**\n\nC++ was created by Bjarne Stroustrup in 1979. It is a powerful, efficient, and widely used programming language because:\n- It supports both **procedural** and **object-oriented programming (OOP)**.\n- It provides **high performance and memory control**.\n- It is used in **system software, game development, embedded systems, and high-performance applications**.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a Programming Paradigm, and Why is it Important?\n\nA **programming paradigm** is a fundamental style of programming that dictates how solutions are structured. Some common paradigms are:\n\n- **Imperative Programming**\n\n  - Focuses on **how** to perform tasks by changing the program's state through statements.\n  - Example:\n\n    ```cpp\n    int sum = 0;\n    for (int i = 1; i \u003c= 5; i++) {\n        sum += i;\n    }\n    ```\n\n- **Object-Oriented Programming (OOP)**\n  - Focuses on using objects and classes to structure programs.\n\n- **Procedural Programming**\n  - Breaks down tasks into procedures (functions), emphasizing reusable code.\n  - A subset of imperative programming.\n\n- **Functional Programming**\n\n  - Focuses on **what** to do rather than **how** to do it. It treats computation as the evaluation of mathematical functions.\n  - Example:\n\n    ```cpp\n    auto square = [](int x) { return x * x; };\n    std::cout \u003c\u003c square(5);  // Output: 25\n    ```\n\n- **Declarative Programming**\n\n  - Focuses on **what** needs to be done, not how. It often involves querying data.\n  - Example:\n\n    ```sql\n    SELECT name FROM students WHERE grade \u003e 90;\n    ```\n\n### Why is it Important?\nUnderstanding paradigms helps developers write **better-structured, efficient, and maintainable code**.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## How Does C++ Differ from C?\n\n- **C++** is an extension of **C** that introduces additional features like **Object-Oriented Programming (OOP)**, **function overloading**, **templates**, and **exception handling**.\n- While **C** is primarily a **procedural** programming language, **C++** supports both **procedural and object-oriented programming paradigms**.\n\n| Feature                | C                             | C++                               |\n|------------------------|-----------------------------|-----------------------------------|\n| **Programming Paradigm** | Procedural                  | Procedural + Object-Oriented      |\n| **Data Encapsulation** | No                            | Yes (Classes \u0026 Objects)           |\n| **Standard Library**   | Limited                       | Rich Standard Library (STL)       |\n| **Memory Management**  | Manual                        | Supports RAII (Smart Pointers)    |\n| **Function Overloading** | No                          | Yes                               |\n| **Operator Overloading** | No                          | Yes                               |\n| **Exception Handling**  | No                          | Yes (Try-Catch Blocks)           |\n| **Templates**          | No                            | Yes (Generic Programming)         |\n| **Namespace Support**  | No                            | Yes                               |\n| **Usage**              | System Programming           | System + Application Development  |\n\n### Major Enhancements in C++\n\n#### 1. **Object-Oriented Programming (OOP)**\nC++ introduces **classes and objects**, allowing encapsulation, inheritance, and polymorphism.\n\n#### 2. **Function Overloading**\nC++ allows multiple functions with the same name but different parameters.\n\n#### 3. **Operator Overloading**\nC++ allows operators to be overloaded to work with user-defined data types.\n\n#### 4. **Exception Handling**\nC++ provides a structured way to handle runtime errors.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the File Structure in a C++ Program?\n\nIn C++, the organization of files is crucial for managing and structuring code effectively:\n\n- **Header Files** (`.h` or `.hpp`): These files contain declarations for functions, classes, and other identifiers. `#include\u003ciostream\u003e` includes the standard library for input and output operations. Header files promote code reuse and modularity by allowing shared declarations across multiple source files.\n\n- **Source Files** (`.cpp`): These files contain the definitions of the functions and classes declared in header files. They provide the implementation details and include the necessary header files.\n\n- **Main Function**: The entry point of a C++ program is the `main` function, where the execution of the program begins.\n\nA typical **C++ program file structure** consists of:\n\n1. **Header Files (`.h`)** – Contain function declarations and macros.\n2. **Source Files (`.cpp`)** – Contain the actual implementation of functions and classes.\n3. **Main File (`main.cpp`)** – The entry point of a C++ program.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Difference Between Low-Level and High-Level Programming Languages?\n\nProgramming languages can be categorized into **low-level** and **high-level** based on their abstraction from machine code.\n\n### **High-Level Languages (Easy to Use)**\nThink of **Google Search** – you type a query and get results without knowing how Google works internally.\nHigh-level languages work similarly – they are **easier to read, write, and understand**, abstracting complex hardware details.\n\n### **Low-Level Languages (More Control)**\nImagine opening a computer and manually controlling its parts instead of just using a search engine.\nLow-level languages work **closer to machine code**, giving **direct control** over hardware but requiring a deep understanding of how computers work.\n\n| Feature              | Low-Level Languages         | High-Level Languages       |\n|----------------------|----------------------------|----------------------------|\n| **Abstraction**      | Close to machine code      | More human-readable        |\n| **Ease of Use**      | Harder to write \u0026 understand | Easier to write \u0026 maintain |\n| **Performance**      | Very fast (direct hardware control) | Slightly slower due to abstraction |\n| **Examples**        | Assembly, C                | C++, Python, Java          |\n| **Memory Management** | Manual (direct access)    | Automatic (Garbage Collection) |\n\n#### Examples of Low \u0026 High-Level Languages\n\n```assembly\n\u003c!-- Low-Level Language (Assembly) --\u003e\nMOV AX, 05    ; Move value 5 into register AX\nADD AX, 03    ; Add 3 to AX\n```\n- Directly tells the processor what to do step-by-step.\n\n```python\n# High-Level Language (Python)\nx = 5\ny = 3\nprint(x + y)\n```\n- Easier to understand and does not require knowledge of computer hardware.\n\n#### Is C++ Low-Level or High-Level?\n\n**C++ is both!**\n- It allows direct memory access like low-level languages.\n- It provides abstraction \u0026 object-oriented features like high-level languages.\n\n- **Low-level languages** are **fast and powerful**, but **harder to write**.\n- **High-level languages** are **easier to use**, but **slightly less efficient**.\n- **C++ gives you both speed and simplicity!** 🚀\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Variables and Comments, and Why are They Used?\n\n### What are Variables?\n\n- A **variable** is a named storage location used to store data.\n- Variables can hold different types of data, such as:\n    - **int → Whole numbers (e.g., 25)**\n    - **float → Decimal numbers (e.g., 3.14)**\n    - **char → Single characters (e.g., 'A')**\n\n- Think of **variables** as **labeled boxes** where you store information.\n    - For example, if you have a box labeled `age`, you can store a number inside it to represent someone's age.\n\n```cpp\nint age = 25;  // A variable storing an integer value\n```\n\n### What are Comments?\n\n- **Comments** are like sticky notes in your code.\n- They don't affect how the program runs but help you (or others) understand the code better.\n\n**Why Use Comments?**\n\n- Improve code readability\n- Explain complex logic\n- Help with debugging\n\n**Types of Comments:**\n\n#### 1. **Single-Line Comment**\n- Used for short explanations.\n\n```cpp\n// This is a single-line comment\nint x = 10;  // Storing the value 10 in x\n```\n\n#### 2. **Multi-Line Comment**\n- Used for longer explanations.\n\n```cpp\n/* This is a\n   multi-line comment */\nint y = 20;\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Variable Scope, and How Does it Affect Code Execution?\n\n### What is Variable Scope?\n\n- The **scope** of a variable defines **where it can be accessed** in a program.\n- Think of it like a **room**: you can only use the items inside that room.\n- Similarly, a variable can only be used within the part of the program where it is declared.\n\n### Types of Variable Scope:\n\n#### 1. **Local Variables**\n- Declared **inside a function**.\n- Can **only be accessed within** that function.\n- Like a **key** that only works in one room.\n\n```cpp\nvoid myFunction() {\n    int localVar = 5;  // Local variable\n    cout \u003c\u003c localVar;  // ✅ Accessible here\n}\ncout \u003c\u003c localVar;  // ❌ ERROR: localVar is not accessible outside\n```\n\n#### 2. **Global Variables**\n- Declared outside all functions.\n- Accessible anywhere in the program.\n- Like a master key that opens all rooms.\n\n```cpp\nint globalVar = 10;  // Global variable\n\nvoid myFunction() {\n    cout \u003c\u003c globalVar;  // ✅ Accessible here\n}\n\nint main() {\n    myFunction();\n    cout \u003c\u003c globalVar;  // ✅ Accessible here too\n}\n```\n\n#### 3. **Block Scope**\n- Variables declared inside `{}` only exist within that block.\n- Like items inside a drawer—you can’t use them outside.\n\n```cpp\nint main() {\n    {\n        int blockVar = 20;\n        cout \u003c\u003c blockVar;  // ✅ Accessible here\n    }\n    cout \u003c\u003c blockVar;  // ❌ ERROR: blockVar is out of scope\n}\n```\n\n#### 4. ** Static Scope**\n- Variables declared with static inside a function retain their value between function calls.\n- Like a notepad that remembers its last written value.\n\n```cpp\nvoid myFunction() {\n    static int count = 0;  // Static variable\n    count++;\n    cout \u003c\u003c count \u003c\u003c endl;\n}\n\nint main() {\n    myFunction();  // Output: 1\n    myFunction();  // Output: 2\n    myFunction();  // Output: 3\n}\n```\n\n- **Local variables** → Limited to a function.\n- **Global variables** → Accessible throughout the program.\n- **Block scope** → Limited to `{}` blocks.\n- **Static variables** → Remember their value between function calls.\n\n- **Use global variables sparingly!** They make debugging harder.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Data Types in C++, and How Are They Classified?\n\nData types define the kind of data a variable can store. In C++, they are classified into three main groups:\n\n### 1. **Built-in Data Types**\nThese are the basic types provided by C++.\n\n- `int` → Stores whole numbers (e.g., `int x = 10;`).\n- `float` → Stores decimal numbers (e.g., `float y = 3.14;`).\n- `char` → Stores single characters (e.g., `char c = 'A';`).\n- `double` → Stores large or precise decimal numbers.\n- `bool` → Stores `true` or `false` values.\n\n### 2. **User-Defined Data Types**\nThese allow creating custom data types.\n\n- `struct` → Groups different types together (e.g., name, age, address).\n- `union` → Stores different data types, but only one at a time.\n- `enum` → Defines named values (e.g., days of the week).\n\n### 3. **Derived Data Types**\nThese are based on built-in types.\n\n- `array` → Collection of same-type values (e.g., `int arr[5];`).\n- `pointer` → Stores the address of another variable (e.g., `int *ptr;`).\n- `function` → Block of reusable code performing a specific task.\n\n- **Choosing the right data type helps optimize memory and performance!**\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What Are Reserved Keywords in C++, and Why Are They Restricted?\n\n- Reserved keywords are special words with predefined meanings in C++.\n- They **cannot** be used as variable names, function names, or other identifiers because they serve specific purposes in the language.\n\n### Why Are They Restricted?\n- They have a **predefined** role in the language.\n- Using them incorrectly can **cause errors**.\n- They help define variables, control flow, and manage functions.\n\n| Category  | Keywords |\n|-----------|------------------------------------------------|\n| **Data Types** | `int`, `float`, `double`, `char`, `bool`, `void` |\n| **Control Flow** | `if`, `else`, `switch`, `case`, `default` |\n| **Loops** | `for`, `while`, `do` |\n| **Functions** | `return`, `void` |\n| **Class \u0026 Struct** | `class`, `struct`, `public`, `private`, `protected` |\n| **Operators** | `\u003c\u003c` (insertion operator -\u003e used for output in streams (like printing to the screen)), `\u003e\u003e` (extraction operator -\u003e used for input in streams (like reading input from the user)) |\n\n- **❌ You cannot use reserved keywords as variable or function names.**\n```cpp\n  int return = 5; // ❌ Error: \"return\" is a reserved keyword.\n```\n\n- **✅ Use descriptive names instead**\n```cpp\nint result = 5; // ✅ Correct usage.\n```\n\n- Understanding reserved keywords helps in writing error-free and efficient code!\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Operators and Their Different Types?\n\n**Operators** are symbols that perform operations on variables and values, such as calculations, comparisons, and logical operations.\n\n### **Different types of operators:**\n\n#### 1. **Arithmetic Operators**:\n   These are used for basic mathematical operations.\n\n- `+` : Addition (e.g., `a + b` adds `a` and `b`)\n- `-` : Subtraction (e.g., `a - b` subtracts `b` from `a`)\n- `*` : Multiplication (e.g., `a * b` multiplies `a` by `b`)\n- `/` : Division (e.g., `a / b` divides `a` by `b`)\n- `%` : Modulus (e.g., `a % b` gives the remainder of `a` divided by `b`)\n- `++` : Increment (e.g., `a++` increases `a` by 1)\n- `--` : Decrement (e.g., `a--` decreases `a` by 1)\n\n#### 2. **Assignment Operators**:\n   These operators are used to assign values to variables.\n\n- `=` : Basic assignment (e.g., `a = 10` assigns `10` to `a`)\n- `+=` : Add and assign (e.g., `a += 5` is equivalent to `a = a + 5`)\n- `-=` : Subtract and assign (e.g., `a -= 3` is equivalent to `a = a - 3`)\n- `*=` : Multiply and assign (e.g., `a *= 2` is equivalent to `a = a * 2`)\n- `/=` : Divide and assign (e.g., `a /= 4` is equivalent to `a = a / 4`)\n- `%=` : Modulus and assign (e.g., `a %= 3` is equivalent to `a = a % 3`)\n\n#### 3. **Comparison Operators**:\n   These operators are used to compare two values and return a boolean result.\n\n- `==` : Equal to (e.g., `a == b` checks if `a` is equal to `b`)\n- `!=` : Not equal to (e.g., `a != b` checks if `a` is not equal to `b`)\n- `\u003e` : Greater than (e.g., `a \u003e b` checks if `a` is greater than `b`)\n- `\u003c` : Less than (e.g., `a \u003c b` checks if `a` is less than `b`)\n- `\u003e=` : Greater than or equal to (e.g., `a \u003e= b` checks if `a` is greater than or equal to `b`)\n- `\u003c=` : Less than or equal to (e.g., `a \u003c= b` checks if `a` is less than or equal to `b`)\n\n#### 4. **Logical Operators**:\n   These operators are used to combine or invert boolean expressions.\n\n- `\u0026\u0026` : Logical AND (e.g., `(a == b) \u0026\u0026 (a \u003e c)` is true if both conditions are true)\n- `||` : Logical OR (e.g., `(a == b) || (a \u003e c)` is true if at least one condition is true)\n- `!` : Logical NOT (e.g., `!(a == b)` is true if the condition is false)\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Difference Between `float`, `double`, and `long double` Literals?\n\n**`float`**:\n\n- **Precision**: Holds single-precision floating-point numbers.\n- **Memory**: Typically takes up 4 bytes.\n- **Use case**: Ideal for storing numbers that do not require high precision.\n\n```cpp\nfloat x = 3.14f; // `3.14f` is a `float` literal (the `f` suffix indicates it's a `float`).\n```\n\n**`double`**:\n\n- **Precision**: Holds double-precision floating-point numbers, providing more accuracy than `float`.\n- **Memory**: Typically takes up 8 bytes.\n- **Use case**: Best for calculations requiring higher precision.\n\n```cpp\ndouble b = 2.718; // 2.718` is a `double` literal (by default, floating-point literals like `3.14` are treated as `double`).\n```\n`\n\n**`long double`**:\n\n- **Precision**: Holds extended-precision floating-point numbers, offering even more precision and a larger range than `double`.\n- **Memory**: Typically uses 12 or 16 bytes, depending on the system.\n- **Use case**: Useful for high-precision calculations, especially in scientific computations.\n\n```cpp\nlong double c = 3.141592653L; // `3.141592653L` (the `L` suffix indicates a `long double`).\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Typecasting?\n\n**Typecasting** is the process of **converting** a variable from one data type to another. This is useful when:\n- Performing operations that require **specific data types**.\n- Ensuring **compatibility** between different data types.\n\n### Types of Typecasting\n- **Implicit Typecasting (Automatic Conversion)** – Performed by the **compiler** automatically.\n- **Explicit Typecasting (Manual Conversion)** – Done using the **(type) operator**.\n\n### Methods of Typecasting\n- **C-style cast** → `(float)a` (Converts `a` to a `float`)\n- **Functional cast** → `float(a)` (Another way to convert `a` to `float`)\n\n```cpp\nint main() {\n    int a = 10;\n    double b = a;  // Implicit conversion\n\n    double c = 3.14;\n    int d = (int)c;  // Explicit conversion\n\n    cout \u003c\u003c \"Implicit: \" \u003c\u003c b \u003c\u003c endl;\n    cout \u003c\u003c \"Explicit: \" \u003c\u003c d \u003c\u003c endl;\n}\n```\n\n### Why Use Typecasting?\n- Avoids data loss when converting between types.\n- Allows mixed-type operations.\n- Ensures precision in calculations.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## How Do You Use the Scope Resolution Operator?\n\nThe **scope resolution operator (`::`)** helps access **global** variables, functions, or namespace members when there's a **naming conflict** with local variables or class members.\n\n### When to Use `::`?\n- **Access Global Variables** → When a local variable has the **same name**.\n- **Define Class Functions Outside the Class** → Helps in organizing code.\n- **Access Namespace Members** → Avoids **naming conflicts**.\n\n```cpp\nint value = 10; // Global variable\n\nclass Example {\npublic:\n    int value; // Local variable\n\n    void show() {\n        cout \u003c\u003c \"Local value: \" \u003c\u003c value \u003c\u003c endl;\n        cout \u003c\u003c \"Global value: \" \u003c\u003c ::value \u003c\u003c endl; // Access global variable\n    }\n};\n\nint main() {\n    Example obj;\n    obj.show();\n}\n```\n\n```cpp\nclass Car {\npublic:\n    void show(); // Function declaration\n};\n\n// Function definition outside the class using `::`\nvoid Car::show() {\n    cout \u003c\u003c \"Car is running!\" \u003c\u003c endl;\n}\n\nint main() {\n    Car myCar;\n    myCar.show();\n}\n```\n\n```cpp\n// Define two namespaces with the same function name\nnamespace English {\n    void greet() {\n        std::cout \u003c\u003c \"Hello!\" \u003c\u003c std::endl;\n    }\n}\n\nnamespace French {\n    void greet() {\n        std::cout \u003c\u003c \"Bonjour!\" \u003c\u003c std::endl;\n    }\n}\n\nint main() {\n    English::greet(); // Calls English version\n    French::greet();  // Calls French version\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Constants, Manipulators, and Operator Precedence?\n\n### 1. **Constants**\n  Constants are unchangeable; once a constant variable is initialized in a program, its value cannot be changed afterwards.\n\n  ```cpp\n  const int MAX = 100;\n  // MAX = 200; // This would cause a compile-time error because MAX is a constant\n  ```\n\n### 2. **Manipulators**\n  Manipulators are used for formatting output:\n\n  - `endl`: Moves to the next line.\n  - `setw`: Specifies the width of the output.\n\n  ```cpp\n  #include \u003ciostream\u003e\n  #include \u003ciomanip\u003e  // For setw\n  int main() {\n  std::cout \u003c\u003c \"Hello\";\n  std::cout \u003c\u003c std::endl; // Moves to the next line\n  std::cout \u003c\u003c std::setw(10) \u003c\u003c 123 \u003c\u003c std::endl; // Sets width for output\n  }\n  ```\n\n### 3. **Operator Precedence \u0026 Operator Associativity**\n\n**Operators** in C++ follow a specific **order of execution** when evaluating expressions.\n- Understanding **operator precedence** and **associativity** helps prevent unexpected results in calculations.\n\n#### 1. **Operator Precedence**\n\n- Determines **which operator** is evaluated first in an expression.\n\nIn `int result = a * b + c;`, multiplication (`*`) has **higher precedence** than addition (`+`).\n\n```cpp\nint main() {\n    int a = 5, b = 10, c = 15;\n    int result = a * b + c; // Multiplication happens first: (5 * 10) + 15 = 50 + 15 = 65\n    cout \u003c\u003c \"Result: \" \u003c\u003c result \u003c\u003c endl;\n}\n```\n\n#### 2. **Operator Associativity**\n\n**Defines how operators of the same precedence are evaluated in an expression.\n\n#### Types of Associativity:\n\n##### **Left-to-right → Most operators (like +, -, *, /) follow this rule.**\n\n- `Left-to-right Associativity` Subtraction (-) is left associative, so a - b - c is evaluated as (a - b) - c.\n\n```cpp\nint main() {\n    int a = 10, b = 5, c = 3;\n    int result = a - b - c; // Evaluated as (10 - 5) - 3 = 5 - 3 = 2\n    cout \u003c\u003c \"Result: \" \u003c\u003c result \u003c\u003c endl;\n}\n```\n\n##### **Right-to-left → Assignment (=) and some unary operators follow this rule.**\n\n- Assignment (=) is right associative, so a = b = c is evaluated as a = (b = c).\n\n```cpp\nint main() {\n    int a, b, c = 10;\n    a = b = c;  // Evaluated as b = c first, then a = b\n    cout \u003c\u003c \"a: \" \u003c\u003c a \u003c\u003c \", b: \" \u003c\u003c b \u003c\u003c \", c: \" \u003c\u003c c \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Control Structures?\n\nControl structures **manage the flow of execution** within a program.\n- They allow decision-making, looping, and altering the normal flow of execution.\n\n### 1. **Sequence Structure**\n\nExecutes instructions **sequentially**, one after another.\n\n```cpp\nint a = 5;\nint b = 10;\nint sum = a + b;\ncout \u003c\u003c \"Sum: \" \u003c\u003c sum \u003c\u003c endl;\n```\n\n### 2. **Selection Structure**\n\nControls the flow of execution based on conditions.\n\n- Implemented using if-else statements or switch-case statements.\n\n```cpp\nint a = 5;\nif (a \u003e 0) {\nstd::cout \u003c\u003c \"Positive number\" \u003c\u003c std::endl;\n} else {\nstd::cout \u003c\u003c \"Non-positive number\" \u003c\u003c std::endl;\n}\n```\n\n```cpp\nint day = 3;\nswitch (day) {\n    case 1:\n        std::cout \u003c\u003c \"Monday\" \u003c\u003c std::endl;\n        break;\n    case 2:\n        std::cout \u003c\u003c \"Tuesday\" \u003c\u003c std::endl;\n        break;\n    default:\n        std::cout \u003c\u003c \"Weekend\" \u003c\u003c std::endl;\n}\n```\n\n### 3. **Iteration Statements (Loops)**\n\nRepeats a block of code until a condition becomes false.\n\n```cpp\nint i = 0;\nwhile (i \u003c 5) {\n    std::cout \u003c\u003c i \u003c\u003c std::endl;\n    i++;\n}\n```\n\n### 4. **Jump Statements**\n\nAlters the normal flow of execution.\n\n#### Break Statement\n\n-  Exits the loop.\n\n```cpp\nfor (int i = 0; i \u003c 5; i++) {\n    if (i == 3) break;\n    cout \u003c\u003c i \u003c\u003c endl;\n}\n// Output: 0 1 2\n```\n\n#### Continue Statement\n\n- Skips the current iteration.\n\n```cpp\nfor (int i = 0; i \u003c 5; i++) {\n    if (i == 3) continue;\n    cout \u003c\u003c i \u003c\u003c endl;\n}\n// Output: 0 1 2 4\n```\n\n####  Return Statement\n\n- Exits from the function.\n\n```cpp\nvoid greet() {\n    cout \u003c\u003c \"Hello!\" \u003c\u003c endl;\n    return; // Function ends here\n}\n```\n\n#### Goto Statement\n\n- Jumps to a labeled statement. (Not recommended in modern C++)\n\n```cpp\nint i = 0;\nstart:\ncout \u003c\u003c i \u003c\u003c endl;\ni++;\nif (i \u003c 3) goto start; // Jumps back to \"start\"\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are the differences between for, while, and do-while loops?\n\n### 1. **For Loop**\n\n- Ideal for situations where the number of iterations is known beforehand.\n\n  ```cpp\n  for (initialization; condition; increment/decrement) {\n      // code to be executed\n  }\n  ```\n\n### 2. **While Loop**\n\n- Useful when the number of iterations is not known and depends on a condition being met.\n\n  ```cpp\n  while (condition) {\n      // code to be executed\n  }\n  ```\n\n### 3. **Do-While Loop**\n\n- Similar to the while loop, but the condition is evaluated after the code block executes, ensuring that the loop body is executed at least once.\n\n  ```cpp\n  do {\n      // code to be executed\n  } while (condition);\n  ```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the difference between the break and continue statements?\n\n### 1. **Break Statement**\n\n- Terminates the loop entirely.\n\n  ```cpp\n  for (int i = 0; i \u003c 10; i++) {\n      if (i == 5) {\n          break; // Exits the loop when i is 5\n      }\n      std::cout \u003c\u003c i \u003c\u003c \" \";\n  }\n  ```\n\n### 2. **Continue Statement**\n\n- Skips the current iteration of the loop and proceeds with the next iteration.\n\n  ```cpp\n  for (int i = 0; i \u003c 10; i++) {\n      if (i == 5) {\n          continue; // Skips the rest of the loop body when i is 5\n      }\n      cout \u003c\u003c i \u003c\u003c \" \";\n  }\n  ```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a pointer and how is it used?\n\nA pointer is a data type that holds the address of another data type. The `\u0026` operator is called the \"address of\" operator, and the `*` operator is called the \"dereference\" operator.\n\n\n```cpp\n// Define a variable and a pointer to it\nint a = 3;\nint* b = \u0026a; // Pointer b holds the address of a\n\n// Display the address and value of a using pointer b\nstd::cout \u003c\u003c \"The address of a is \" \u003c\u003c \u0026a \u003c\u003c std::endl;\nstd::cout \u003c\u003c \"The address of a is \" \u003c\u003c b \u003c\u003c std::endl;\nstd::cout \u003c\u003c \"The value at address b is \" \u003c\u003c *b \u003c\u003c std::endl;\n```\n\n**Benefits:**\n\n1. Dynamic Memory Allocation\n\nPointers are used to allocate and deallocate memory dynamically.\n\n```cpp\nvoid dynamicMemoryAllocation() {\n    int* ptr = new int; // Allocating memory dynamically\n    *ptr = 42;          // Assigning a value\n    cout \u003c\u003c \"Dynamic Memory Allocation: \" \u003c\u003c *ptr \u003c\u003c endl;\n    delete ptr;         // Deallocating memory\n}\n```\n\n2. Container Access\n\nPointers can point to arrays, structs, or other containers, and can pass the address of these containers to functions.\n\n```cpp\nvoid containerAccess(int* arr, int size) {\n    std::cout \u003c\u003c \"Container Access: \";\n    for (int i = 0; i \u003c size; i++) {\n        std::cout \u003c\u003c *(arr + i) \u003c\u003c \" \"; // Accessing array elements using a pointer\n    }\n    std::cout \u003c\u003c std::endl;\n}\n```\n\n3. Return Multiple Values\n\nPointers can be used to return multiple values from a function.\n\n```cpp\nvoid returnMultipleValues(int a, int b, int* sum, int* product) {\n    *sum = a + b;          // Assigning sum to the pointer\n    *product = a * b;      // Assigning product to the pointer\n}\n```\n\n**Pointer to Pointer**\n\nA pointer to pointer is a variable that stores the address of another pointer. In simple terms, it’s a pointer that points to another pointer, which in turn points to a value.\n\n```cpp\nint a = 5;          // A normal variable\nint* ptr = \u0026a;      // A pointer that stores the address of 'a'\nint** ptr2 = \u0026ptr;  // A pointer to pointer, it stores the address of 'ptr'\n\n// Printing the value of 'a' through ptr and ptr2\ncout \u003c\u003c \"Value of a: \" \u003c\u003c a \u003c\u003c endl;      // Direct value of 'a'\ncout \u003c\u003c \"Value of a through ptr: \" \u003c\u003c *ptr \u003c\u003c endl;  // Dereferencing ptr to get 'a'\ncout \u003c\u003c \"Value of a through ptr2: \" \u003c\u003c **ptr2 \u003c\u003c endl; // Dereferencing ptr2 twice to get 'a'\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the concept of Null Pointer?\n\n### What is a Null Pointer?\n\n- A **null pointer** is a pointer that does not point to any valid memory location.\n- It is used to indicate that the pointer is not currently holding any object or address.\n\n- It is assigned the value NULL or nullptr (C++11 onwards).\n- Helps in avoiding dangling pointers (pointers pointing to invalid memory).\n- Used to check if a pointer is valid before dereferencing it.\n\n```cpp\nint* ptr = NULL;  // Null pointer\nif (ptr == NULL) {\n    cout \u003c\u003c \"Pointer is NULL!\" \u003c\u003c endl;\n} else {\n    cout \u003c\u003c \"Pointer is not NULL!\" \u003c\u003c endl;\n}\n// ptr == NULL means the pointer is empty and does not point to valid memory.\n```\n\n### Why use nullptr instead of NULL?\n\n- `NULL` is an integer constant (0), while `nullptr` is a true pointer constant.\n- `nullptr` is type-safe, making it a better choice.\n\n```cpp\nint* ptr = nullptr;  // nullptr is preferred over NULL\n```\n\n### Common Use Cases of Null Pointers\n\n#### 1. **Avoid Dangling Pointers**\n\nA dangling pointer occurs when a pointer still holds a memory address of a deleted object.\n\n```cpp\nint* ptr = new int(10);\ndelete ptr;  // Memory is freed\nptr = NULL;  // Avoid dangling pointer\n// Setting ptr = NULL; ensures that it doesn’t point to an invalid memory location.\n```\n\n#### 2. **Checking for Valid Memory Before Dereferencing**\n\n```cpp\nint* ptr = NULL;\nif (ptr) {\n    cout \u003c\u003c *ptr \u003c\u003c endl;  // Won't execute if ptr is NULL\n} else {\n    cout \u003c\u003c \"Pointer is NULL, cannot dereference!\" \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the concept of Garbage Collection?\n\n### What is Garbage Collection?\n\n- Garbage collection is the **process of reclaiming unused memory** to prevent memory leaks. However, **C++ does not have built-in garbage collection** like Java or Python!\n- Instead, programmers must manually manage memory using `new` and `delete`.\n\n### Why is Garbage Collection Important?\n\nWithout proper memory management, programs can suffer from:\n-  **Memory leaks** (allocated memory is never freed)\n-  **Dangling pointers** (pointers referring to deleted memory)\n-  **Memory fragmentation** (small unused memory blocks slow down the program)\n\n```cpp\n// Example of Memory Leak\nvoid memoryLeak() {\n    int* ptr = new int(10);  // Memory allocated on heap\n    cout \u003c\u003c \"Value: \" \u003c\u003c *ptr \u003c\u003c endl;\n    // No delete statement -\u003e Memory leak occurs!\n}\n\nint main() {\n    memoryLeak();\n}\n```\n\n**Problem:** Memory is allocated with `new`, but never deallocated with `delete`, causing a **memory leak**.\n\n### Manual Garbage Collection in C++\n\n#### 1️. **Free Memory Using `delete`**\n\n```cpp\nint* ptr = new int(10);\ndelete ptr;  // Memory freed\nptr = NULL;  // Avoids dangling pointer\n```\n- `Always **free dynamically allocated memory** to prevent leaks.`\n\n#### 2️. **Use Smart Pointers (C++11)**\n\nSmart pointers automatically manage memory by deleting unused objects.\n\n##### 1. **Unique Pointer (`std::unique_ptr`)**\n\n- Manages **exclusive ownership** of an object.\n- Automatically deletes memory when it goes out of scope.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cmemory\u003e  // Required for smart pointers\nusing namespace std;\n\nint main() {\n    unique_ptr\u003cint\u003e ptr = make_unique\u003cint\u003e(20); // No need to use `new` or `delete`\n    cout \u003c\u003c \"Value: \" \u003c\u003c *ptr \u003c\u003c endl;\n}  // `ptr` goes out of scope, memory is automatically freed!\n```\n\n##### 2. **Shared Pointer (`std::shared_ptr`)**\n\n- Allows **multiple pointers** to share ownership.\n- Deletes memory when the **last reference** is removed.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cmemory\u003e\nusing namespace std;\n\nint main() {\n    shared_ptr\u003cint\u003e p1 = make_shared\u003cint\u003e(30);\n    shared_ptr\u003cint\u003e p2 = p1; // Both share ownership\n\n    cout \u003c\u003c \"Value: \" \u003c\u003c *p1 \u003c\u003c endl;\n}  // Memory is freed when `p1` and `p2` go out of scope.\n```\n\n- **C++ does NOT have automatic garbage collection** – manual memory management is required.\n- **Memory leaks occur if allocated memory is not freed using `delete`.**\n- **Use smart pointers (`unique_ptr`, `shared_ptr`) to avoid manual memory management.**\n- **Always assign `ptr = NULL;` after `delete` to prevent dangling pointers.**\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is an Array, and How are Arrays and Pointers Related?\n\n### What is an Array?\nAn **array** is a collection of elements of the same data type stored in contiguous memory locations.\n\n```cpp\nint arr[] = {1, 2, 3};\nint *ptr = arr;  // Pointer to first element\ncout \u003c\u003c *(ptr + 1); // Output: 2\n```\n\n### Arrays and Pointers\n\n**Array Name as a Pointer:**\n\n- In C++, the name of an array acts as a pointer to the **first element** of the array.\n- This means the array name itself holds the **memory address** of the first item in the array.\n\n- `arr` is equivalent to `\u0026arr[0]`.\n- `*(arr + i)` is the same as `arr[i]`.\n\n```cpp\nint main() {\n    int marks[] = {23, 45, 56, 89}; // Array with 4 integers\n    int* p = marks; // Pointer to first element\n\n    // Loop through the array using pointer arithmetic\n    for (int i = 0; i \u003c 4; i++) {\n        cout \u003c\u003c *(p + i) \u003c\u003c \" \";  // Accessing each element using pointer\n    }\n\n    cout \u003c\u003c endl;\n\n    // Additional pointer arithmetic examples\n    cout \u003c\u003c *(p++) \u003c\u003c endl; // Output first element and move pointer\n    cout \u003c\u003c *(++p) \u003c\u003c endl; // Move pointer first, then output value\n    cout \u003c\u003c \"The value of *p is \" \u003c\u003c *p \u003c\u003c endl;\n    cout \u003c\u003c \"The value of *(p+1) is \" \u003c\u003c *(p+1) \u003c\u003c endl;\n    cout \u003c\u003c \"The value of *(p+2) is \" \u003c\u003c *(p+2) \u003c\u003c endl;\n    cout \u003c\u003c \"The value of *(p+3) is \" \u003c\u003c *(p+3) \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Struct, Union, and Enums in C++?\n\n### 1. **Struct**\n\nA **struct** is a user-defined data type in C++ that allows you to group different types of data together. It is similar to an array, but unlike arrays which store data of the same type, a struct can store data of multiple types.\n\n```cpp\nstruct employee {\n    int eId;       // Employee ID\n    char favChar;  // Favorite character\n    int salary;    // Salary\n};\n\nint main() {\n    employee Chilli; // Creating an instance of the struct\n    // Access struct members\n    Chilli.eId = 1;\n    Chilli.favChar = 'H';\n    Chilli.salary = 50000;\n}\n```\n\n### 2. **Union**\n\nA `union` is similar to a struct, but it provides better memory management. All members of a union share the same memory location, so only one member can be used at a time.\n\n```cpp\nunion money {\n    int rice;     // Amount of rice\n    char car;     // Car type\n    float pounds; // Pounds of something\n};\n\nint main() {\n    money m1;\n    m1.rice = 34;  // Assigning value to rice\n    cout \u003c\u003c m1.rice; // Output the value of rice\n}\n```\n\n### 3. **Enum**\n\nAn `enum` (enumeration) is a user-defined data type that consists of named constants representing integral values. It makes programs more readable and manageable by defining a set of named values.\n\n```cpp\nenum Meal {\n    breakfast, // 0\n    lunch,     // 1\n    dinner     // 2\n};\n\nint main() {\n    Meal m1 = dinner; // Setting enum value\n    if (m1 == 2) {\n        cout \u003c\u003c \"The value of dinner is \" \u003c\u003c dinner \u003c\u003c endl; // Output value of dinner\n    }\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Function and Function Prototypes in C++?\n\n### 1. **Function**\n\n- A **function** is a block of code that performs a specific task.\n- It helps make the code **reusable, modular, and easier to debug**.\n\n```cpp\n// Function definition\nint sum(int a, int b) {\n    return a + b;\n}\n\nint main() {\n    int result = sum(5, 3); // Calling the function\n    cout \u003c\u003c \"Sum is: \" \u003c\u003c result \u003c\u003c endl;\n}\n```\n\n### 2. **Function Prototypes**\n\n- A **function prototype** is a declaration of a function before defining it.\n- It tells the compiler the function's name, return type, and parameters before the actual function implementation.\n\n```cpp\n// Function prototype (declaration)\nint sum(int a, int b);\n\n// `int sum` → This is the **function signature**, where:\n// - `sum` is the **function name**.\n// - `int` before `sum` is the **return type**, meaning this function will return an `int` value.\n\n// `(int a, int b)` → This is the **parameter list**, where:\n// - `int a` and `int b` are **parameters** (also called **formal parameters**).\n// - These define the expected input types when the function is called.\n\n\nint main() {\n    int result = sum(5, 3); // Function call\n    cout \u003c\u003c \"Sum is: \" \u003c\u003c result \u003c\u003c endl;\n}\n\n// Function definition\nint sum(int a, int b) {\n    return a + b;\n}\n```\n\n- Prototypes must match function definitions\n- Prototypes allow calling functions before they are defined\n\n```cpp\nint sum(int a, b);   // ❌ Incorrect: Missing type for 'b'\nint sum(int, int);   // ✅ Acceptable but less descriptive\n```\n\n- Using function prototypes improves code organization and avoids errors when calling functions before they are defined.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Actual and Formal Parameters?\n\n### 1. **Formal Parameters**\n\n- **Formal parameters** are the variables declared in a function's definition.\n- They act as placeholders for the values that will be passed when calling the function.\n- They exist **only inside the function**.\n\n### 2. **Actual Parameters**\n\n- **Actual parameters** are the real values or variables passed to a function when it is called.\n- They provide the function with specific data to process.\n\n```cpp\n// Function definition with formal parameters 'a' and 'b'\nvoid add(int a, int b) {\n    cout \u003c\u003c \"Sum is: \" \u003c\u003c a + b \u003c\u003c endl; // 'a' and 'b' are formal parameters\n}\n\nint main() {\n    int num1 = 5, num2 = 3;\n    add(num1, num2); // num1 and num2 are actual parameters\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What does it mean by Call by Value, Call by Reference, \u0026 Call by Pointer?\n\n### 1. **Call by Value**\n\n- A **copy** of the actual parameter is passed to the function.\n- Changes made inside the function **do not affect** the original values.\n\n```cpp\nint sum(int a, int b){\n    int c = a + b;\n    return c;\n}\n\n// This will not swap a and b\nvoid swap(int a, int b){\n    int temp = a;\n    a = b;\n    b = temp;\n}\n\nint main(){\n    int x = 4, y = 5;\n    cout \u003c\u003c \"The value of x is \" \u003c\u003c x \u003c\u003c \" and the value of y is \" \u003c\u003c y \u003c\u003c endl;\n    swap(x, y); // This will not swap x and y\n    cout \u003c\u003c \"The value of x is \" \u003c\u003c x \u003c\u003c \" and the value of y is \" \u003c\u003c y \u003c\u003c endl;\n}\n```\n\n### 2. **Call by Pointer**\n\n- A **memory address **(pointer) of the actual parameters is passed.\n- Changes made inside the function affect the original values.\n\n```cpp\n// Call by Pointer\nvoid swapPointer(int* a, int* b) {\n    int temp = *a;\n    *a = *b;\n    *b = temp;\n}\n\nint main() {\n    int x = 4, y = 5;\n    cout \u003c\u003c \"Before swap: x = \" \u003c\u003c x \u003c\u003c \", y = \" \u003c\u003c y \u003c\u003c endl;\n    swapPointer(\u0026x, \u0026y); // Passing memory addresses\n    cout \u003c\u003c \"After swap: x = \" \u003c\u003c x \u003c\u003c \", y = \" \u003c\u003c y \u003c\u003c endl;\n}\n```\n\n### 3. **Call by Reference**\n\n- A **reference** (alias) to the actual parameter is passed.\n- Changes made inside the function affect the original values.\n\n```cpp\n// Call by Reference using C++ reference variables\nvoid swapReferenceVar(int \u0026a, int \u0026b) {\n    int temp = a;\n    a = b;\n    b = temp;\n}\n\nint main() {\n    int x = 4, y = 5;\n    cout \u003c\u003c \"Before swap: x = \" \u003c\u003c x \u003c\u003c \", y = \" \u003c\u003c y \u003c\u003c endl;\n    swapReferenceVar(x, y); // Call by Reference\n    cout \u003c\u003c \"After swap: x = \" \u003c\u003c x \u003c\u003c \", y = \" \u003c\u003c y \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Static Variables \u0026 Functions?\n\n### 1. **Static Variable**\n\nA **static variable** is a variable that belongs to the **class** rather than an **instance**. It is shared among all objects of the class, meaning only **one copy** of the variable exists.\n\n- **Shared Across Objects**: A static variable is common to all objects.\n- **Declared Inside the Class**: But must be **defined outside** the class.\n- **Memory Allocation**: Allocated once, at program start, and deallocated at program end.\n- **Access**: Accessed using the **class name** with the `::` scope resolution operator.\n\n```cpp\nclass Counter {\npublic:\n    static int count; // Static variable declaration\n\n    Counter() {\n        count++; // Increment count for each object created\n    }\n\n    static int getCount() { // Static function\n        return count;\n    }\n};\n\n// Define and initialize static variable\nint Counter::count = 0;\n\nint main() {\n    Counter obj1, obj2, obj3;\n\n    // Access static function using class name\n    cout \u003c\u003c \"Total objects created: \" \u003c\u003c Counter::getCount() \u003c\u003c endl;\n}\n```\n\n### 2. **What is a Static Function?**\n\nA **static function** is a function that belongs to the **class**, not to any specific object. It can **only access static variables** and **other static functions**.\n\n- ❌ **Cannot access non-static members**.\n- ✅ **Does not require an object** to be called.\n- ❌ **Cannot use** the `this` pointer.\n- ✅ **Can be called using the class name**.\n\n```cpp\nclass Circle {\n    int radius;\n    static const float Pi;\n\npublic:\n    void setRadius(int r) {\n        radius = r;\n    }\n\n    int getRadius() const {\n        return radius;\n    }\n\n    // Static function to get Pi value\n    static float getPi() {\n        return Pi;\n    }\n};\n\n// Define static constant\nconst float Circle::Pi = 3.14159;\n\nint main() {\n    // Access static function without creating an object\n    cout \u003c\u003c \"Value of Pi: \" \u003c\u003c Circle::getPi() \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Inline Functions, Default Arguments, \u0026 Constant Arguments?\n\n### 1. **Inline Functions**\n\n**Inline functions** are used to reduce the overhead of function calls. Instead of jumping to the function's memory location, the compiler replaces the function call with the function's actual code at **compile-time**.\n\n**When to Use?**\n- Useful for **small functions** to improve execution speed.\n- Not recommended for **functions with static variables**, as they may lead to inefficiency.\n\n```cpp\ninline int product(int a, int b){\n    return a * b;\n}\n\nint main(){\n    int a = 5, b = 10;\n    cout \u003c\u003c \"The product of \" \u003c\u003c a \u003c\u003c \" and \" \u003c\u003c b \u003c\u003c \" is \" \u003c\u003c product(a, b) \u003c\u003c endl;\n}\n```\n\n### 2. **Default Arguments**\n\n**Default arguments** allow functions to be called with fewer parameters than defined. If a value is not provided, the default value is used.\n\n- Default arguments must be specified in the function prototype or definition.\n- Default arguments should be placed after all required parameters.\n\n```cpp\nfloat moneyReceived(int currentMoney, float factor = 1.04) {\n    return currentMoney * factor;\n}\n\nint main() {\n    int money = 100000;\n\n    cout \u003c\u003c \"If you have \" \u003c\u003c money \u003c\u003c \" Rs in your bank account, you will receive \"\n         \u003c\u003c moneyReceived(money) \u003c\u003c \" Rs after 1 year\" \u003c\u003c endl;\n\n    cout \u003c\u003c \"For VIP: If you have \" \u003c\u003c money \u003c\u003c \" Rs in your bank account, you will receive \"\n         \u003c\u003c moneyReceived(money, 1.1) \u003c\u003c \" Rs after 1 year\" \u003c\u003c endl;\n}\n```\n\n### 3. **Constant Arguments**\n\n- **Constant arguments** prevent a function from modifying the values of the arguments. This ensures data integrity and avoids accidental changes inside the function.\n\n- When passing read-only data to a function.\n- When working with pointers to constant values to avoid accidental modification.\n\n```cpp\nint strlen(const char *p) {\n    int length = 0;\n    while (*p != '\\0') {\n        length++;\n        p++;\n    }\n    return length;\n}\n\nint main() {\n    const char *str = \"Hello, World!\";\n    cout \u003c\u003c \"The length of the string is \" \u003c\u003c strlen(str) \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Recursion and Recursive Functions?\n\n**Recursion** is a process where a function **calls itself** to solve a problem. A function that does this is known as a **recursive function**.\n\n### Key Components of Recursion:\n1. **Base Case**\n   - The condition that **stops** recursion.\n   - Prevents infinite recursive calls.\n\n2. **Recursive Case**\n   - The function **calls itself** with modified arguments.\n   - Continues until the base case is met.\n\n```cpp\n// Recursive function to calculate factorial\nint factorial(int n){\n    if (n \u003c= 1){\n        return 1; // Base case\n    }\n    return n * factorial(n - 1); // Recursive case\n}\n\nint main(){\n    int number = 5;\n    cout \u003c\u003c \"The factorial of \" \u003c\u003c number \u003c\u003c \" is \" \u003c\u003c factorial(number) \u003c\u003c endl;\n}\n```\n\n### How Recursion Works (Step-by-Step)\n\n- For factorial(5), the recursive calls work like this:\n```cpp\nfactorial(5) → 5 * factorial(4)\nfactorial(4) → 4 * factorial(3)\nfactorial(3) → 3 * factorial(2)\nfactorial(2) → 2 * factorial(1)\nfactorial(1) → 1 (Base Case)\n```\n- Now, returning back:\n```cpp\nfactorial(2) = 2 * 1 = 2\nfactorial(3) = 3 * 2 = 6\nfactorial(4) = 4 * 6 = 24\nfactorial(5) = 5 * 24 = 120\n```\n\n### When to Use Recursion?\n- When the problem can be divided into similar subproblems.\n- When using loops makes the solution more complex.\n\n❌ Avoid recursion if it causes stack overflow due to excessive function calls.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Function Overloading?\n\n- **Function Overloading** allows multiple functions to have the **same name** but different **parameters** (either in number or type).\n- This enables functions to perform similar tasks while accepting different types or numbers of arguments.\n\n### How Does Function Overloading Work?\nFunction overloading works by **changing:**\n1. **Number of parameters**\n2. **Type of parameters**\n*(Changing only the return type is **not enough** to overload a function!)*\n\n### **Function Overloading Based on Number of Parameters**\n```cpp\n// Function to add two numbers\nint sum(int a, int b) {\n    cout \u003c\u003c \"Using function with 2 parameters\" \u003c\u003c endl;\n    return a + b;\n}\n\n// Function to add three numbers\nint sum(int a, int b, int c) {\n    cout \u003c\u003c \"Using function with 3 parameters\" \u003c\u003c endl;\n    return a + b + c;\n}\n\nint main() {\n    cout \u003c\u003c sum(10, 20) \u003c\u003c endl;    // Calls the function with 2 parameters\n    cout \u003c\u003c sum(10, 20, 30) \u003c\u003c endl; // Calls the function with 3 parameters\n}\n```\n\n### **Function Overloading Based on Parameter Type**\n```cpp\n// Function to calculate the square of an integer\nint square(int x) {\n    return x * x;\n}\n\n// Function to calculate the square of a double\ndouble square(double x) {\n    return x * x;\n}\n\nint main() {\n    cout \u003c\u003c \"Square of 5 (int): \" \u003c\u003c square(5) \u003c\u003c endl;\n    cout \u003c\u003c \"Square of 5.5 (double): \" \u003c\u003c square(5.5) \u003c\u003c endl;\n}\n```\n\n### ❌ What Does NOT Count as Function Overloading?\n**Changing Only the Return Type**\n```cpp\nint func(int x);  // Function 1\ndouble func(int x);  // ❌ Error: Only return type is different\n```\n\n| Feature | Description |\n|---------|-------------|\n| **Function Overloading** | Same function name, different **number/type of parameters** |\n| **Valid Overloading** | ✅ Change in number of parameters or data type |\n| **Invalid Overloading** | ❌ Changing only the return type |\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n\n## What is OOP?\n\n- OOP stands for Object-Oriented Programming.\n- It's a **programming paradigm** or way of writing code that uses \"objects\" to represent real-world things or concepts.\n- Each object can have its own data and functions (called methods) that work with that data.\n- It is easier to relate real world entities to the OOP.\n\n### **Key OOP Concepts:**\n1. **Class** – A blueprint for objects.\n2. **Object** – An instance of a class.\n3. **Encapsulation** – Restricts direct access to object data, ensuring security or Hiding internal/private details.\n4. **Abstraction** –Hides complex details, exposing only essential features.\n5. **Inheritance** – Reusing code from parent classes.\n6. **Polymorphism** – Enables objects to be treated as instances of a common parent class.\n\n```cpp\nclass Car {\npublic:\n    string brand;\n    void show() { cout \u003c\u003c \"Brand: \" \u003c\u003c brand; }\n};\nint main() {\n    Car myCar;\n    myCar.brand = \"Toyota\";\n    myCar.show();\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## Some Visual Things about OOP\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"1. OOP.png\" width=\"48%\" height=\"250px\" alt=\"OOP Image 1\"\u003e\n  \u003cimg src=\"2. OOP.png\" width=\"48%\" height=\"250px\" alt=\"OOP Image 2\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"3. OOP.png\" width=\"97%\" height=\"400px\" alt=\"OOP Image 3\"\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"4. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 4\"\u003e\n  \u003cimg src=\"5. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 5\"\u003e\n  \u003cimg src=\"6. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 6\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"7. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 7\"\u003e\n  \u003cimg src=\"8. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 8\"\u003e\n  \u003cimg src=\"9. OOP.jpg\" width=\"32.5%\" height=\"350px\" alt=\"OOP Image 9\"\u003e\n\u003c/p\u003e\n\n---\n\n## Why OOP? Purpose of Implementing OOP?\n\nOOP provides several benefits that make software development efficient and maintainable:\n\n- **Modularity** – Breaks programs into smaller, manageable parts.\n- **Code Reusability** – Inheritance reduces code duplication.\n- **Scalability** – Efficiently builds and extends large systems.\n- **Maintainability** – Modular structure simplifies debugging and updates.\n- **Real-world Modeling** – Represents real-world entities as objects.\n- **Parallel Development** – Teams can work on different objects independently.\n- **Data Security** – Encapsulation restricts unnecessary access to data.\n\n**OOP helps write **organized, reusable, and maintainable code**, making it a preferred choice for large-scale software development.**\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## Why is OOP so popular?\n\nOOPs, programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well.\n\n#### **Key Reasons for OOP's Popularity**\n- **Modularity** – Breaks programs into smaller, manageable parts.\n- **Code Reusability** – **Inheritance** reduces duplication and promotes efficiency.\n- **Scalability** – Easily extends and adapts to growing software needs.\n- **Maintainability** – Modular structure simplifies debugging and updates.\n- **Real-world Modeling** – Represents real-world entities as objects.\n- **Parallel Development** – Teams can work on different modules independently.\n- **Data Security** – **Encapsulation** restricts unauthorized access.\n\n#### **Not only that, the main pillar of OOPs**\n1. **Encapsulation** – Binds data and methods together, restricting direct access.\n2. **Abstraction** – Hides unnecessary details, exposing only essential features.\n3. **Inheritance** – Enables reusability by deriving new classes from existing ones.\n4. **Polymorphism** – Allows one interface, multiple implementations for flexibility.\n\nMakes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are the Pros and Cons of Object-Oriented Programming (OOP)?\n\nObject-Oriented Programming (OOP) is a popular paradigm, but like any approach, it has both advantages and drawbacks. Below is a structured comparison:\n\n### Pros of OOP\n| **Advantage**         | **Explanation** |\n|----------------------|----------------|\n| **Modularity**        | Breaks programs into smaller, manageable parts, making debugging and maintenance easier. |\n| **Code Reusability**  | Inheritance allows efficient reuse of existing code, reducing redundancy. |\n| **Scalability**       | Easily extendable for larger projects and adaptable to changing requirements. |\n| **Maintainability**   | Organized structure makes it easier to debug and update code. |\n| **Data Security**     | Encapsulation restricts unauthorized access, ensuring better data protection. |\n| **Real-World Modeling** | Represents real-world entities effectively, making software design intuitive. |\n| **Parallel Development** | Different modules can be worked on independently, improving team collaboration. |\n| **Extensibility**     | Polymorphism allows modifying or extending functionalities without altering existing code. |\n\n### Cons of OOP\n| **Disadvantage**        | **Explanation** |\n|-----------------------|----------------|\n| **Requires Skilled Programmers** | Developers need a strong understanding of objects, classes, and OOP concepts. |\n| **Not Always Suitable** | Might not be the best choice for small-scale or simple problems. |\n| **Larger Codebase**   | OOP programs tend to have more lines of code compared to procedural programming. |\n| **More Memory Consumption** | Object creation and dynamic features may lead to higher memory usage. |\n| **More Planning Required** | The design phase is complex and requires proper planning before implementation. |\n| **Slower Execution Speed** | Due to abstraction layers, OOP can be slightly slower than procedural programming. |\n| **Documentation Dependency** | Understanding OOP code without proper documentation can be difficult. |\n| **Longer Development Time** | Designing classes, relationships, and interactions requires more effort upfront. |\n\n- **OOP is great for large-scale applications** due to its modularity, reusability, and scalability.\n- **However, it requires more planning and can be resource-intensive** compared to procedural programming.\n\nOOP remains a widely used paradigm in major programming languages like **C++, Java, and Python**, making it an essential concept for software developers.\n\n**Additional Advantages of OOP:**\n- Follows a **bottom-up approach**, making code more structured.\n- **Encapsulation** avoids unnecessary data exposure and enhances security.\n- OOP **forces extensive design planning**, leading to better architecture and fewer flaws.\n- **Breaks down complex problems** into manageable chunks.\n- **Enhances productivity** by minimizing complexity and allowing easy redesigns without affecting other functionalities.\n- Provides **efficient modeling of real-world entities**, making programming more intuitive.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Difference Between Object-Oriented Programming vs Structural Programming?\n\n| **Object-Oriented Programming (OOP)**                          | **Structural Programming**                                                                  |\n|---------------------------------------------------------------|--------------------------------------------------------------------------------------------|\n| **Follows a bottom-up approach** – Development starts with objects and their interactions. | **Follows a top-down approach** – Development starts with defining functions and procedures. |\n| **Supports data hiding** – Uses encapsulation to restrict direct access to data. | **Does not support data hiding** – Data is freely accessible within the program. |\n| **Best suited for complex and large-scale applications.** | **Best suited for moderate or small-scale applications.** |\n| **Code reusability** – Inheritance and polymorphism reduce redundancy. | **Limited code reusability** – Functions can be reused, but there is no built-in inheritance. |\n| **Based on objects and classes** – Emphasizes real-world modeling. | **Based on procedures and functions** – Focuses on breaking a problem into smaller tasks. |\n| **Provides better security** – Data is controlled through access modifiers. | **Less secure** – Data is shared across functions, increasing exposure. |\n| **Higher abstraction and flexibility** – Uses encapsulation, polymorphism, and abstraction for better control. | **Less abstraction and flexibility** – Code organization is more rigid and procedural. |\n| **Focuses on data and behavior (methods).** | **Focuses on process and step-by-step execution.** |\n\n- **OOP** is ideal for complex, scalable applications with reusable components and better security.\n- **Structural Programming** is suitable for simpler applications that require a straightforward, procedural approach.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Difference Between Procedure-Oriented Programming (POP) and Object-Oriented Programming (OOP)?\n\n| **Procedure-Oriented Programming (POP)** | **Object-Oriented Programming (OOP)** |\n|------------------------------------------|------------------------------------------|\n| Centers around functions or procedures. | Centers around objects that bundle data and methods. |\n| Data is often global and less secure. | Data is encapsulated within objects, providing better security. |\n| Programs are structured as a sequence of steps or procedures. | Programs are structured around objects and classes. |\n| Limited reusability of code due to a lack of modularity and encapsulation. | Promotes reusability through mechanisms like inheritance and polymorphism. |\n| Less suitable for complex applications. | More suitable for complex applications. |\n| Focuses on function calls. | Focuses on message passing between objects. |\n\n**Limitations of OOP:**\n- Programs written using OOP tend to be larger than those using procedural programming.\n- Requires significant planning and pre-work before implementation.\n- Without proper documentation, OOP code can be challenging to understand.\n- Object-oriented programs may consume more memory due to dynamic features.\n- Not ideal for small, simple problems.\n- Development may take longer due to class and object structuring.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a Pure Object-Oriented Language?\n\nA programming language is called a **pure object-oriented language** if it treats everything inside the program as an object. Unlike hybrid OOP languages, pure OOP languages do not support primitive data types (e.g., integers, floats, characters) outside the object model.\n\nA pure OOP language must satisfy the following properties:\n\n- **Encapsulation** – Data hiding through access modifiers.\n- **Inheritance** – Ability to derive new classes from existing ones.\n- **Polymorphism** – Same interface, different implementations.\n- **Abstraction** – Hiding implementation details and exposing only necessary functionalities.\n- **All Predefined Types Are Objects** – No primitive data types exist outside objects.\n- **All User-Defined Types Are Objects** – Every custom type must be an object.\n- **All Operations Are Performed Through Methods** – Direct access to variables is restricted; all interactions happen through object methods.\n\n### Examples of Pure OOP Languages\n- **Smalltalk**\n- **Eiffel**\n- **Ruby**\n\nLanguages like **Java, C++, Python, and C#** are not purely object-oriented because they allow primitive data types like `int`, `char`, and `float` outside the object model.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a Struct?\n\n- A struct (structure) is a user-defined data type in C++ that groups related variables under a single name.\n- Structs are typically used for lightweight objects that hold data without requiring encapsulation or functionality.\n- Unlike classes, struct members are `public` by default.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nstruct Person {\n    string name;\n    int age;\n};\n\nint main() {\n    Person p1;\n    p1.name = \"Alice\";\n    p1.age = 30;\n    cout \u003c\u003c \"Name: \" \u003c\u003c p1.name \u003c\u003c \", Age: \" \u003c\u003c p1.age \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a Class and Why Do We Need It in OOP?\n\n- Class is a building block of OOP.\n- It is a user defined data type.\n- It is a blueprint or recipe for creating objects in object-oriented programming (OOP).\n- It contains data members (attributes) and member functions (methods) that define the behaviors of objects.\n\n**Why Do We Need It?**\n- **Encapsulation:** Bundles data and methods that operate on the data.\n- **Reusability:** Once defined, a class can create many instances (objects).\n- **Inheritance:** A class can inherit properties and behaviors from other classes.\n- **Abstraction:** Simplifies complex systems by hiding unnecessary details.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Person {\npublic:\n    string name;\n    int age;\n\n    void introduce() {\n        cout \u003c\u003c \"Hello, my name is \" \u003c\u003c name \u003c\u003c \" and I am \" \u003c\u003c age \u003c\u003c \" years old.\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Person p1;\n    p1.name = \"Bob\";\n    p1.age = 25;\n    p1.introduce();\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Class Attributes \u0026 Methods in OOP?\n\nIn Object-Oriented Programming (OOP), **attributes** and **methods** define the characteristics and behavior of an object.\n\n- **Attributes (Member Variables)** - Represent the **state** or properties of an object.\n- **Methods** - Functions inside a class that define the **behavior** of an object.\n\n```cpp\nclass Car {\npublic:\n    // Attributes (Member Variables)\n    string model;\n    int year;\n\n    // Method (Member Function)\n    void display() {\n        cout \u003c\u003c \"Model: \" \u003c\u003c model \u003c\u003c \", Year: \" \u003c\u003c year \u003c\u003c endl;\n    }\n};\n\nint main() {\n    // Creating an object of Car\n    Car car1;\n    car1.model = \"Tesla Model 3\";\n    car1.year = 2023;\n\n    // Calling a method\n    car1.display();\n}\n```\n\n- Attributes store data about an object.\n- Methods define what the object can do.\n- Methods can access and modify an object's attributes.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## Why Use a Class Instead of a Struct?\n\nIn C++, both **classes** and **structs** can be used to create custom data types, but **classes** offer more flexibility and control.\n\n| Feature | **Class** | **Struct** |\n|---------|----------|-----------|\n| **Access Control** | Members are `private` by default. | Members are `public` by default. |\n| **Encapsulation** | Can have private and protected members, restricting access. | No direct access restriction unless explicitly specified. |\n| **Functionality** | Supports methods, constructors, destructors, and operator overloading. | Primarily used for grouping related data, lacks complex functionality. |\n| **Inheritance** | Supports **inheritance** (base and derived classes). | **Does not support inheritance** in the same way as classes. |\n\n```cpp\nclass Person {\nprivate:\n    string name;\n    int age;\n\npublic:\n    // Constructor to initialize the data members\n    Person(string n, int a) : name(n), age(a) {}\n\n    // Member function to display the details\n    void showDetails() {\n        cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c \", Age: \" \u003c\u003c age \u003c\u003c endl;\n    }\n};\n\nint main() {\n    // Creating an object of the class\n    Person p1(\"Charlie\", 28);\n\n    // Calling the member function to show details\n    p1.showDetails();\n}\n```\n\n### Why Use a Class Instead of a Struct?\n\n- **Encapsulation** – Restrict access to sensitive data.\n- **More Functionality** – Supports methods, constructors, and destructors.\n- **Supports Inheritance** – Can extend and modify functionality.\n- **Better Code Organization** – Ideal for complex data structures and OOP.\n\n### When to Use Class vs Struct?\n\n#### Use a class when you need:\n\n- Encapsulation (private members)\n- Inheritance and polymorphism\n- Functions and behaviors in addition to data\n\n#### Use a struct when you need:\n- Simple data storage without complex behavior\n- Lightweight objects for performance optimization\n\n- Structs are ideal for small data models, while classes offer a better, scalable approach for Object-Oriented Programming.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are the Similarities Between Class and Struct?\n\n- Both **group related data** into a single entity.\n- Both can have **member variables** (data members).\n- Both can have **member functions** (methods).\n- Both support **constructors and destructors**.\n- Both allow **operator overloading**.\n- Both can define **static members**.\n- Both can use **access specifiers** (`public`, `private`, `protected`).\n\n```cpp\n// Class Example\nclass ClassExample {\npublic:\n    int x;\n    void show() { cout \u003c\u003c \"Class x: \" \u003c\u003c x \u003c\u003c endl; }\n};\n\n// Struct Example\nstruct StructExample {\n    int y;\n    void show() { cout \u003c\u003c \"Struct y: \" \u003c\u003c y \u003c\u003c endl; }\n};\n\nint main() {\n    ClassExample obj1;\n    obj1.x = 10;\n    obj1.show();\n\n    StructExample obj2;\n    obj2.y = 20;\n    obj2.show();\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Difference Between Class and Struct?\n\n| Feature         | **Class** | **Struct** |\n|----------------|----------|------------|\n| **Default Access** | Members are `private` by default. | Members are `public` by default. |\n| **OOP Features** | Fully supports **inheritance, polymorphism, encapsulation, and abstraction**. | Does **not** support inheritance. |\n| **Functionality** | Can have **constructors, destructors, and member functions**. | Primarily used for **storing data** with limited functionality. |\n\n```cpp\n// Class Example\nclass Person {\nprivate:\n    string name;\npublic:\n    Person(string n) : name(n) {}  // Constructor\n    void display() { cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c endl; } // Method\n};\n\n// Struct Example\nstruct PersonStruct {\n    string name;  // Public by default\n};\n\nint main() {\n    // Using a class\n    Person p1(\"Alice\");\n    p1.display();\n\n    // Using a struct\n    PersonStruct s1;\n    s1.name = \"Bob\";\n    cout \u003c\u003c \"Name: \" \u003c\u003c s1.name \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is a Object and Why Do We Need It in OOP?\n\n- An **object** is an **instance** of a class.\n\n### 🧐 What Does \"Instance\" Mean?\n- An **instance** is a **real, usable version** of a class.\n- Think of a **class** as a **blueprint** and an **object** as the **actual thing created** using that blueprint.\n\n- It represents real-world entities created from a blueprint (class) with properties (data members) and behaviors (member functions). Without objects, a class is just a blueprint and does not hold any actual data.\n\n- Think of a **class** as a **recipe** and an **object** as the actual **dish** made using that recipe. A recipe defines the ingredients and steps, but unless you cook it, the recipe itself is useless!\n\n- **Class = Recipe 📜**\n- **Object = Dish 🍛 (Made from the recipe)**\n\n###  Why Do We Need Objects?\n\nObjects are **crucial in OOP** because they:\n- **Store Data** → A class is just a **template**; objects bring it to **life** by holding real values.\n- **Encapsulate Behavior** → Objects allow actions using their **methods (functions)**.\n- **Enable Modularity** → Promote **code reuse**, better organization, and easy debugging.\n\n```cpp\n// Class Definition\nclass Car {\npublic:\n    string brand;\n    int speed;\n\n    // Method to display car details\n    void showDetails() {\n        cout \u003c\u003c \"Brand: \" \u003c\u003c brand \u003c\u003c \", Speed: \" \u003c\u003c speed \u003c\u003c \" km/h\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Car myCar; // Creating an object of the Car class\n\n    // Assigning values to object properties\n    myCar.brand = \"Toyota\";\n    myCar.speed = 120;\n\n    // Calling the object's method\n    myCar.showDetails();\n}\n```\n\n- A class is just a concept or a template.\n- An instance (or object) is a real, created version of that class.\n- You must create an object to use the class in practice!\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is an Array of Objects?\n\n###  What is an Array of Objects?\n- An **array of objects** is an array where **each element** is an **instance of a class**.\n- Just like an array of integers (`int arr[5]`), we can create an **array of objects** to store multiple instances of a class.\n\n### Why Use an Array of Objects?\n- **Efficient Storage \u0026 Organization** → Store multiple objects in a single array.\n- **Indexed Access** → Access individual objects using their index, just like normal arrays.\n- **Better Code Management** → Helps manage related objects without separate variables.\n\n```cpp\nclass Car {\npublic:\n    string brand;\n    int speed;\n\n    void setData(string b, int s) {\n        brand = b;\n        speed = s;\n    }\n\n    void showDetails() {\n        cout \u003c\u003c \"Brand: \" \u003c\u003c brand \u003c\u003c \", Speed: \" \u003c\u003c speed \u003c\u003c \" km/h\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Car cars[3]; // ✅ Creating an array of 3 Car objects\n\n    // Assign values to each object in the array\n    cars[0].setData(\"Toyota\", 120);\n    cars[1].setData(\"Honda\", 130);\n    cars[2].setData(\"BMW\", 160);\n\n    // Display details of each car using a loop\n    for (int i = 0; i \u003c 3; i++) {\n        cout \u003c\u003c \"Car \" \u003c\u003c i + 1 \u003c\u003c \": \";\n        cars[i].showDetails();\n    }\n}\n```\n\n- Objects can be stored in arrays just like primitive data types.\n- Indexed access makes it easy to manipulate multiple objects.\n- Loops make it efficient to process multiple instances of a class.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## How do you Pass Objects as Function Arguments?\n\nObjects in C++ can be passed to functions in **two ways**:\n\n1. **Pass by Value**: A copy of the object is made, meaning changes inside the function **won’t affect the original object**.\n2. **Pass by Reference**: The function receives a reference to the object, meaning it can **directly modify the original object**.\n\n```cpp\nclass Complex {\n    int a;\n    int b;\n\npublic:\n    // Function to set values of a and b\n    void setData(int v1, int v2) {\n        a = v1;\n        b = v2;\n    }\n\n    // Function to set object data by summing two other objects\n    void setDataBySum(const Complex \u0026o1, const Complex \u0026o2) {\n        a = o1.a + o2.a;\n        b = o1.b + o2.b;\n    }\n\n    // Function to print complex number\n    void printNumber() const {\n        cout \u003c\u003c \"Your complex number is \" \u003c\u003c a \u003c\u003c \" + \" \u003c\u003c b \u003c\u003c \"i\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Complex c1, c2, c3;\n\n    c1.setData(1, 2);\n    c1.printNumber();\n\n    c2.setData(3, 4);\n    c2.printNumber();\n\n    // Passing objects as function arguments\n    c3.setDataBySum(c1, c2);\n    c3.printNumber();\n}\n```\n\n- **Pass by Value** creates a copy of the object, meaning changes inside the function do not affect the original object.\n- **Pass by Reference** (const \u0026) avoids unnecessary copies and allows direct modification.\n- **Function Overloading** can be used to perform different operations on objects.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Pointer to Objects in C++? What are its Purpose and Benefits?\n\n### What is a Pointer to an Object?\n\nIn C++, **pointers** are used to store addresses of both **primitive data types** (like `int`, `float`, `double`) and **objects of user-defined classes**.\nA **pointer to an object** is a special pointer that stores the **memory address** of an object of a class type.\n\n### Purpose of Pointers to Objects\nPointers to objects are widely used in C++ for the following reasons:\n\n**Dynamic Object Creation**:\n- Objects can be created dynamically at runtime using the `new` keyword.\n- This allows more flexibility and efficient memory management.\n\n**Indirect Access**:\n- Objects can be accessed and manipulated indirectly through pointers.\n- Useful when working with dynamically allocated objects or when passing objects to functions.\n\n**Efficient Memory Management**:\n- Reduces unnecessary memory allocation and deallocation.\n- Helps in optimizing memory usage in large-scale applications.\n\n```cpp\nclass Complex {\n    int real, imaginary;\n\npublic:\n    void setData(int a, int b) {\n        real = a;\n        imaginary = b;\n    }\n\n    void getData() {\n        cout \u003c\u003c \"The real part is \" \u003c\u003c real \u003c\u003c endl;\n        cout \u003c\u003c \"The imaginary part is \" \u003c\u003c imaginary \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Complex *ptr = new Complex;  // Dynamically creating an object\n\n    ptr-\u003esetData(1, 54);  // Using -\u003e operator to access members\n    ptr-\u003egetData();\n\n    delete ptr;  // Free allocated memory\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## How is Memory Allocated for Variables, Functions, Member Functions, and Data Members?\n\nMemory allocation happens at different times depending on the type of variable or function. Here's a breakdown:\n\n### 1. Memory Allocation for Variables\n\n| **Variable Type**         | **When Allocated?**          | **Where Stored?**               | **When Deallocated?**            |\n|--------------------------|-----------------------------|--------------------------------|---------------------------------|\n| **Local Variables**      | When function is called     | **Stack**                      | When function returns           |\n| **Global Variables**     | When program starts        | **Data Segment (BSS/Initialized Data)** | When program ends |\n| **Static Variables**     | When program starts (First use) | **Data Segment (BSS/Initialized Data)** | When program ends |\n| **Dynamic Variables (`new`)** | When `new` is called  | **Heap**                        | When `delete` is called         |\n\n### 2. Memory Allocation for Member Variables in a Class\n\n| **Variable Type**         | **When Allocated?**        | **Where Stored?**            | **When Deallocated?**      |\n|--------------------------|---------------------------|-----------------------------|--------------------------|\n| **Non-Static Members**   | When an object is created | **Heap/Stack** (depends on object creation) | When object is destroyed |\n| **Static Members**       | When program starts (First use) | **Data Segment** | When program ends |\n\n```cpp\nclass MyClass {\npublic:\n    int x;  // Non-static (allocated per object)\n    static int count;  // Static (allocated once for all objects)\n\n    MyClass() { x = 0; }\n};\n\nint MyClass::count = 0; // Allocated when the program starts (Data Segment)\n```\n\n### 3.Memory Allocation for Functions\n\n| **Function Type**        | **When Allocated?**       | **Where Stored?**    | **When Deallocated?** |\n|-------------------------|--------------------------|---------------------|----------------------|\n| **Regular Functions**   | When program starts      | **Code Segment**    | Never (Remains throughout execution) |\n| **Member Functions**    | When program starts      | **Code Segment**    | Never |\n| **Virtual Functions (vtable)** | When the first object of a class is created | **Heap (vtable pointer per object)** | When the last object of class is destroyed |\n\n```cpp\nclass Base {\npublic:\n    virtual void show() {} // Stored in vtable\n};\n\nint main() {\n    Base obj; // Allocates vtable pointer in Heap\n}\n```\n\n### 4. Memory Allocation for Objects\n\n| **Object Type**          | **When Allocated?**       | **Where Stored?**    | **When Deallocated?** |\n|-------------------------|--------------------------|---------------------|----------------------|\n| **Automatic Objects** (`MyClass obj;`) | When function is called | **Stack** | When function returns |\n| **Dynamic Objects** (`new MyClass();`) | When `new` is called | **Heap** | When `delete` is called |\n\n```cpp\nint main() {\n    MyClass obj1;  // Stack allocation (Deallocated when function ends)\n    MyClass* obj2 = new MyClass();  // Heap allocation (Must delete manually)\n    delete obj2; // Deallocates obj2\n}\n```\n\n- **Stack** variables exist only inside functions.\n- **Heap** memory must be manually deallocated with `delete`.\n- **Static variables exist throughout the program's execution.\n- **Functions are stored once and never deallocated.\n- **Virtual functions use a vtable allocated on the heap.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What are Access Specifiers in OOP?\n\nAccess specifiers control the visibility of members in a class:\n\n- **Public:** Members are accessible from anywhere in the program.\n- **Private:** Members are accessible only within the class itself.\n- **Protected:** Members are accessible within the class and its derived classes.\n\n```cpp\nclass Person {\nprivate:\n    string name;\n\npublic:\n    Person(string n) : name(n) {}\n\n    void displayName() {\n        cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Person p(\"David\");\n    p.displayName();  // Accessing public method\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Default Access Modifier in a Class?\n\nIn C++, the **default access modifier** for members of a **class** is **private**.\n\n- This means that if you do not explicitly specify an access modifier (`public`, `private`, or `protected`), the members of the class will be **private by default**.\n\nHowever, in a **struct**, the default access modifier is **public**.\n\n```cpp\nclass MyClass {\n    int privateVar; // Default access is private\n\npublic:\n    int publicVar; // Explicitly declared as public\n};\n\nstruct MyStruct {\n    int publicVar; // Default access is public\n};\n\nint main() {\n    MyClass obj1;\n    // obj1.privateVar = 10; // ❌ Error: private member cannot be accessed\n    obj1.publicVar = 20;  // ✅ Allowed\n\n    MyStruct obj2;\n    obj2.publicVar = 30;  // ✅ Allowed (default access in struct is public)\n\n    cout \u003c\u003c \"obj1.publicVar: \" \u003c\u003c obj1.publicVar \u003c\u003c endl;\n    cout \u003c\u003c \"obj2.publicVar: \" \u003c\u003c obj2.publicVar \u003c\u003c endl;\n}\n```\n\n- For **class**, the default access modifier is private.\n- For **struct**, the default access modifier is public.\n- You must `explicitly` use **public** if you want class members to be accessible outside the class.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Sealed Modifier?\n\nA **sealed class** or **sealed modifier** is used to prevent other classes from inheriting from it. In some languages like C# or Java, marking a class as sealed ensures that no class can derive from it.\n\n```csharp\nsealed class MyClass {\n    public void Display() {\n        Console.WriteLine(\"This is a sealed class.\");\n    }\n}\n\n// This will result in a compile-time error:\n// class DerivedClass : MyClass { }  // Error: cannot inherit from sealed class\n```\n\n- In languages like C++, the equivalent would be to simply avoid inheritance by not defining any child classes, as C++ does not have a direct **sealed** keyword.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is Dynamic Memory Allocation (DMA) and the new Keyword? What are Their Purpose and Benefits?\n\n### What is Dynamic Memory Allocation?\nDynamic Memory Allocation (DMA) in C++ allows memory to be **allocated at runtime**, rather than at compile time. This is done using the `new` keyword, which **allocates memory on the heap** and returns a pointer to the allocated space. The allocated memory must be **freed** using the `delete` operator (or smart pointers) to prevent **memory leaks**.\n\nC++ also provides `new[]` and `delete[]` for dynamically **allocating and deallocating arrays**.\n\n### Purpose\n- **Allocates memory on the heap** (instead of the stack).\n- **Returns a pointer** to the allocated memory.\n- **Allows dynamic object creation** and flexible memory management.\n\n### Benefits of Dynamic Memory Allocation\n- **Efficient Memory Usage** – Allocates memory **only when needed**, reducing wastage.\n- **Supports Object-Oriented Programming (OOP)** – Allows creating objects dynamically.\n- **Flexible Array Allocation** – Arrays can be allocated dynamically based on user input.\n- **Lifetime Control** – Objects persist beyond function calls if necessary.\n\n```cpp\nint main() {\n    // Allocating memory for a single integer\n    int* ptr = new int(10);\n    cout \u003c\u003c \"Value: \" \u003c\u003c *ptr \u003c\u003c endl;\n\n    // Allocating memory for an array\n    int* arr = new int[5]{1, 2, 3, 4, 5};\n\n    cout \u003c\u003c \"Array elements: \";\n    for (int i = 0; i \u003c 5; i++) {\n        cout \u003c\u003c arr[i] \u003c\u003c \" \";\n    }\n    cout \u003c\u003c endl;\n\n    // Freeing the allocated memory\n    delete ptr;   // Free single integer\n    delete[] arr; // Free array\n}\n```\n\n- Forgetting to delete dynamically allocated memory results in memory leaks.\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the `delete` What are its Purpose and Benefits?\n\nThe `delete` keyword in C++ is used to **free dynamically allocated memory** that was allocated using the `new` keyword. It ensures that memory allocated on the **heap** is properly released and made available for reuse.\n\n### Purpose\n- **Releases memory allocated with `new`**, preventing memory leaks.\n- Returns the allocated memory back to the **operating system**.\n- Improves memory efficiency, ensuring the program doesn't consume excessive resources.\n\n### Benefits\n**Prevents Memory Leaks** – Ensures memory allocated using `new` is properly deallocated.\n**Efficient Memory Management** – Helps manage heap memory efficiently, especially for large objects and arrays.\n**Avoids Unnecessary Memory Consumption** – Frees up memory for reuse.\n\n```cpp\nint main() {\n    // Dynamically allocate an array of 3 integers\n    int* arr = new int[3];\n\n    arr[0] = 10;\n    arr[1] = 20;\n    arr[2] = 30;\n\n    cout \u003c\u003c \"Before delete: \" \u003c\u003c arr[0] \u003c\u003c \", \" \u003c\u003c arr[1] \u003c\u003c \", \" \u003c\u003c arr[2] \u003c\u003c endl;\n\n    // Free the allocated memory\n    delete[] arr;\n\n    // After deletion, accessing the array leads to undefined behavior\n    cout \u003c\u003c \"After delete (undefined behavior): \" \u003c\u003c arr[0] \u003c\u003c endl;\n}\n```\n\n**[⬆ Back to Top](#table-of-contents)**\n\n---\n\n## What is the Arrow (`-\u003e`) and Dot (`.`) Operator? What is its Purpose or Benefit?\n\nIn C++, the **dot (`.`) operator** and **arrow (`-\u003e`) operator** are used to access **members (variabl","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahadalireach%2Foop.interview.questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahadalireach%2Foop.interview.questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahadalireach%2Foop.interview.questions/lists"}