{"id":16238208,"url":"https://github.com/kanishkrawatt/cpp","last_synced_at":"2026-03-02T21:43:57.693Z","repository":{"id":50086163,"uuid":"518560117","full_name":"Kanishkrawatt/CPP","owner":"Kanishkrawatt","description":" A collection of resources to learn object-oriented programming and related concepts With cpp ","archived":false,"fork":false,"pushed_at":"2023-02-17T06:02:24.000Z","size":2017,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T19:43:24.755Z","etag":null,"topics":["cpp","markdown"],"latest_commit_sha":null,"homepage":"","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/Kanishkrawatt.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}},"created_at":"2022-07-27T17:52:55.000Z","updated_at":"2023-08-25T02:47:03.000Z","dependencies_parsed_at":"2024-10-27T21:22:10.102Z","dependency_job_id":"44056aa1-cda3-4b2d-917b-decc5293b749","html_url":"https://github.com/Kanishkrawatt/CPP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishkrawatt%2FCPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishkrawatt%2FCPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishkrawatt%2FCPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kanishkrawatt%2FCPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kanishkrawatt","download_url":"https://codeload.github.com/Kanishkrawatt/CPP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244006137,"owners_count":20382436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","markdown"],"created_at":"2024-10-10T13:39:20.599Z","updated_at":"2026-03-02T21:43:57.639Z","avatar_url":"https://github.com/Kanishkrawatt.png","language":"C++","readme":"## C++\n\nC++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or \"C with Classes\".\n\nThe language has expanded significantly over time, and modern C++ now has [object-oriented](/Oops), generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language.\n\n| Content                                                           | Other Topics                               | Units                                                                                                                                                |\n| ----------------------------------------------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [Difference between C and C++](#difference-between-c-and-c)       | [Object Oriented Programming(oops)](/Oops) | Unit 1 : [Basic](#difference-between-c-and-c) , [Oops](/Oops)                                                                                                                |\n| [Input and Output in C and C++](#input-and-output-in-c-and-c)     | [Data Structure](\u003c/CPP(DSA)\u003e)              | Unit 2 : [Classes](/Oops/Class/) , [Constructor-Destructors](/Oops/Constructor-Destructor/)                                                          |\n| [Constants in C++](#constants-in-c)                               | [Basic C++](\u003c/CPP(Basic)\u003e)                 | Unit 3 : [Inheritance](/Oops/Inheritance/) , [Polymorphism](/Oops/Polymorphism/) , [Operator Overloading](/Oops/OperatorOverloading/)                |\n| [Literals](#literals)                                             | [Algorithms](/Algorithms)                  | Unit 4 : [Parametric polymorphism](/Oops/ParametricPolymorphism/) , [Exception Handling](/Oops/ExceptionHandling/) , [Streams \u0026Files](/Oops/Stream/) |\n| [Qualifiers](#qualifiers)                                         | [Competitive Questions](/compe)            |\n| [Operators](#operators)                                           |\n| [Reference variable](#reference-variable)                         |\n| [Functions](#functions)                                           |\n| [Default Arguments](#default-arguments)                           |\n| [Inline Function](#inline-function)                               |\n| [Parameter Passing by Value](#parameter-passing-by-value)         |\n| [Parameter Passing by Reference](#parameter-passing-by-reference) |\n| [Parameter Passing by Pointer](#parameter-passing-by-pointer)     |\n| [Constructor/Distructor](/Oops/Constructor-Distructor/readme.md)  |\n| [Inheritance](/Oops/Inheritance/readme.md)                        |\n| [Polymorphism](/Oops/Polymorphism/readme.md)                      |\n| [Operator Overloading](/Oops/OperatorOverloading/readme.md)       |\n| [Virtual Function](/Oops/VirtualFunction/readme.md)               |\n| [Parametric Polymorphism](/Oops/ParametricPolymorphism/readme.md) |\n| [Exception Handling](/Oops/ExceptionHandling/readme.md)           |\n| [Stream](/Oops/Stream/readme.md)                                  |\n\n##### Difference between C and C++\n\n| C                                                                | C++                                                         |\n| ---------------------------------------------------------------- | ----------------------------------------------------------- |\n| C was developed by **Dennis Ritchie** between _1969_ and _1973_. | C++ was developed by **Bjarne stroustrup** in _1979_.       |\n| C is (mostly) a subset of C++.                                   | C++ is (mostly) a superset of C.                            |\n| Is supports Procedural Programming.                              | It Support both Procedural and object Oriented Programming. |\n| It Does not support Information hiding and encapsulation.        | It does support Information hiding and encapsulation.       |\n| It is function-driven language.                                  | It is Object-drivedn language.                              |\n| Standard I/O header is \u003cstdio.h\u003e.                                | Standard I/O header is \u003ciostream.h\u003e.                        |\n| It provides **Malloc()** and **Calloc()** for memory allocation  | It provides **New** operator for memory allocation          |\n| It provides **free()** for Memory de-allocation.                 | It provides **Delete**                                      |\n\n##### Input and Output in C and C++\n\n```cpp\n// Output(print) in C\nint a = 10;\nprintf(\"%d\",a);\n\n// Output(print) in C++\nint a = 10;\ncout\u003c\u003ca\u003c\u003cendl;\n\n// Input value  in C\nint a;\nscanf(\"%d\",a);\n\n// Input value in C++\nint a;\ncin\u003e\u003ea;\n```\n\n##### Constants in C++\n\n**const** modifier is used to create constants.\u003cbr\u003e\nVariables whose value cannot be changed once they are initalized.\n\n```cpp\nSyntax:\n    const type variable_name = value;\n\n```\n\n```cpp\nexample:\nint main()\n{\n    const int i = 10;\n    i = 20   // Error ! Cann't change value of i\n             // (since it is a constant)\n}\n\n```\n\n##### Literals\n\nLiterals are data used for representing fixed point values that we can directly use in the code.\n\n```cpp\nexample:\n10, 20, 3.14, 'a', etc.\n\n```\n\n##### There are 4 types of literals\n\n- Integer Literal\n\n  ```\n  - Decimal Literal\n      examples:\n          0, -1, 100, 20, etc.\n  - Octal Literal (starts with 0)\n      examples:\n          045, 065, 043 , etc.\n  - Hexadecimal Literal (starts with 0x)\n      examples:\n          0x8f, 0x2a, 0x721, etc.\n  - Floating Point Literal\n      It has a integer part, a decimal point,\n      a fractional part , and an exponent part.\n      example:\n          3.14134, 4e-11 , 1E-5,\n\n  ```\n\n- Boolean Literal\n  ```cpp\n  - true\n  - false\n  ```\n- Character Literal\n  ```cpp\n  - 'a'\n  - 'b'\n  - 'c'\n  ```\n- String Literal\n  ```cpp\n  - \"Hello World\"\n  - \"C++\"\n  ```\n\n##### Qualifiers\n\nQualifiers are used to modify the meaning of the type.\n\n- **const** : It is used to create constants.\n- **volatile** : It is used to modify the variable.\n- **restrict** : It is used to restrict the pointer.\n\n##### Operators\n\nOperators are used to perform operations on variables and values.\n\n- **Arithmetic Operators**\n  ```cpp\n  - Addition (+)\n  - Subtraction (-)\n  - Multiplication (*)\n  - Division (/)\n  - Modulus (%)\n  - Increment (++)\n  - Decrement (--)\n  ```\n- **Relational Operators**\n  ```cpp\n  - Equal to (==)\n  - Not equal to (!=)\n  - Greater than (\u003e)\n  - Less than (\u003c)\n  - Greater than or equal to (\u003e=)\n  - Less than or equal to (\u003c=)\n  ```\n- **Logical Operators**\n  ```cpp\n  - Logical AND (\u0026\u0026)\n  - Logical OR (||)\n  - Logical NOT (!)\n  ```\n- **Bitwise Operators**\n  ```cpp\n  - Bitwise AND (\u0026)\n  - Bitwise OR (|)\n  - Bitwise XOR (^)\n  - Bitwise NOT (~)\n  - Bitwise Left Shift (\u003c\u003c)\n  - Bitwise Right Shift (\u003e\u003e)\n  ```\n- **Assignment Operators**\n  ```cpp\n  - Assignment (=)\n  - Addition Assignment (+=)\n  - Subtraction Assignment (-=)\n  - Multiplication Assignment (*=)\n  - Division Assignment (/=)\n  - Modulus Assignment (%=)\n  - Left Shift Assignment (\u003c\u003c=)\n  - Right Shift Assignment (\u003e\u003e=)\n  - Bitwise AND Assignment (\u0026=)\n  - Bitwise OR Assignment (|=)\n  - Bitwise XOR Assignment (^=)\n  ```\n- **Miscellaneous Operators**\n  ```cpp\n  - Sizeof\n  - Comma (,)\n  - Ternary (?)\n  - Pointer to member (.*)\n  - Member of pointer (-\u003e*)\n  ```\n- **Conditional Operator**\n  ```cpp\n  Syntax:\n      condition ? expression1 : expression2;\n  ```\n  ```cpp\n  example:\n      int a = 10;\n      int b = 20;\n      int c = a \u003e b ? a : b;\n      cout\u003c\u003cc\u003c\u003cendl;\n  ```\n- **sizeof Operator**\n  ```cpp\n  Syntax:\n      sizeof (type)\n  ```\n  ```cpp\n  example:\n      int a = 10;\n      cout\u003c\u003csizeof(a)\u003c\u003cendl;\n  ```\n- **Comma Operator**\n  ```cpp\n  Syntax:\n      expression1, expression2, expression3, ....\n  ```\n  ```cpp\n  example:\n      int a = 10, b = 20, c = 30;\n      cout\u003c\u003ca\u003c\u003cb\u003c\u003cc\u003c\u003cendl;\n  ```\n- **Pointer to member Operator**\n  ```cpp\n  Syntax:\n      object.*pointer_to_member\n  ```\n  ```cpp\n  example:\n      class A\n      {\n          int a;\n          public:\n              void set(int x)\n              {\n                  a = x;\n              }\n              int get()\n              {\n                  return a;\n              }\n      };\n      int main()\n      {\n          A obj;\n          obj.set(10);\n          int A::*p = \u0026A::a;\n          cout\u003c\u003cobj.*p\u003c\u003cendl;\n      }\n  ```\n- **Member of pointer Operator**\n  ```cpp\n  Syntax:\n      pointer-\u003e*pointer_to_member\n  ```\n  ```cpp\n  example:\n      class A\n      {\n          int a;\n          public:\n              void set(int x)\n              {\n                  a = x;\n              }\n              int get()\n              {\n                  return a;\n              }\n      };\n      int main()\n      {\n          A obj;\n          obj.set(10);\n          int A::*p = \u0026A::a;\n          cout\u003c\u003cobj-\u003e*p\u003c\u003cendl;\n      }\n  ```\n- **Type Casting Operator**\n  ```cpp\n  Syntax:\n      (type) expression\n  ```\n  ```cpp\n  example:\n      int a = 10;\n      float b = (float) a;\n      cout\u003c\u003cb\u003c\u003cendl;\n  ```\n- **Precedence and Associativity of Operators**\n  ```cpp\n  Precedence:\n      1. ()\n      2. ++, --\n      3. *, /, %\n      4. +, -\n      5. \u003c\u003c, \u003e\u003e\n      6. \u003c, \u003c=, \u003e, \u003e=\n      7. ==, !=\n      8. \u0026\n      9. ^\n      10. |\n      11. \u0026\u0026\n      12. ||\n      13. ?:\n      14. =, +=, -=, *=, /=, %=, \u003c\u003c=, \u003e\u003e=, \u0026=, ^=, |=\n  ```\n  ```cpp\n  Associativity:\n      1. Left to Right\n      2. Right to Left\n  ```\n\n#### Reference variable\n\nReference variable is an alias/another name of another variable.\n\n```cpp\nSyntax:\n    type \u0026reference_variable = variable;\n```\n\n```cpp\nexample:\nint a = 10;\nint \u0026b = a;\n```\n\n#### Functions\n\nA function is a group of statements that together perform a task.\n\n```cpp\nSyntax:\n    return_type function_name (parameter list)\n    {\n        body of the function\n    }\n```\n\n```cpp\nexample:\n    int add(int a, int b)\n    {\n        return a + b;\n    }\n```\n\n##### Default Arguments\n\nDefault arguments are used to provide default\nvalues to the parameters of a function.\n\n```cpp\nSyntax:\n    return_type function_name (parameter list = default_value)\n    {\n        body of the function\n    }\n```\n\n```cpp\nexample:\n    int add(int a, int b = 10)\n    {\n        return a + b;\n    }\n    int main(){\n        cout\u003c\u003cadd(10)\u003c\u003cendl; // This will print 20\n    }\n```\n\n##### Inline Function\n\nInline function is an enhancement feature that improves the execution time and speed of a program.\n\n```cpp\nSyntax:\n    inline return_type function_name (parameter list)\n    {\n        body of the function\n    }\n```\n\n```cpp\nexample:\n    inline int add(int a, int b)\n    {\n        return a + b;\n    }\n    int main(){\n        cout\u003c\u003cadd(10, 20)\u003c\u003cendl; // This will print 30\n    }\n```\n\n##### Parameter Passing by Value\n\nWhen a function is called, the values of the actual parameters are copied to the formal parameters of the function. This is called parameter passing by value.\n\n```cpp\nexample:\n    void swap(int a, int b)\n    {\n        int temp = a;\n        a = b;\n        b = temp;\n    }\n    int main(){\n        int a = 10, b = 20;\n        swap(a, b);\n        cout\u003c\u003ca\u003c\u003cb\u003c\u003cendl; // This will print 10 20\n    }\n```\n\n##### Parameter Passing by Reference\n\nWhen a function is called, It will give the address of the actual parameters to the formal parameters of the function. This is called parameter passing by reference.\n\nIt allows a function to modify a variable without having to create a copy of it.\n\n```cpp\nexample:\n    void swap(int \u0026a, int \u0026b)\n    {\n        int temp = a;\n        a = b;\n        b = temp;\n    }\n    int main(){\n        int a = 10, b = 20;\n        swap(a, b);\n        cout\u003c\u003ca\u003c\u003cb\u003c\u003cendl; // This will print 20 10\n    }\n```\n\n##### Parameter Passing by Pointer\n\nWhen a function is called, It will pass the memory location of the actual parameters to the formal parameters of the function. This is called parameter passing by pointer.\n\n```cpp\nexample:\n    void swap(int *a, int *b)\n    {\n        int temp = *a;\n        *a = *b;\n        *b = temp;\n    }\n    int main(){\n        int a = 10, b = 20;\n        swap(\u0026a, \u0026b);\n        cout\u003c\u003ca\u003c\u003cb\u003c\u003cendl; // This will print 20 10\n    }\n```\n\n**Difference between Parameter Passing by Reference and Pointer**\n\n| Parameter Passing by Reference                           | Parameter Passing by Pointer        |\n| -------------------------------------------------------- | ----------------------------------- |\n| It is **easy** to use.                                   | It is **difficult** to use.         |\n| It is **faster** than pointer.                           | It is **slower** than reference.    |\n| It is **safer** than pointer. because it cannot be NULL. | It is **not safer** than reference. |\n\n##### New and Delete Operator\n\nNew and delete operator are used to allocate and deallocate memory dynamically.\n\n```cpp\nSyntax:\n    new data_type;\n    delete pointer;\n```\n\n```cpp\nexample:\n    int *p = new int;\n    *p = 10;\n    cout\u003c\u003c*p\u003c\u003cendl; // This will print 10\n    delete p;\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanishkrawatt%2Fcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanishkrawatt%2Fcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanishkrawatt%2Fcpp/lists"}