{"id":24496435,"url":"https://github.com/kubgus/cpp-cheatsheet","last_synced_at":"2025-12-29T19:36:38.841Z","repository":{"id":209090606,"uuid":"723214946","full_name":"kubgus/cpp-cheatsheet","owner":"kubgus","description":"A collection of C++ snippets that explain how the language works.","archived":false,"fork":false,"pushed_at":"2024-01-02T12:46:55.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T21:17:25.698Z","etag":null,"topics":["cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kubgus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-11-25T00:48:41.000Z","updated_at":"2024-09-10T06:48:42.000Z","dependencies_parsed_at":"2024-01-01T19:28:56.424Z","dependency_job_id":null,"html_url":"https://github.com/kubgus/cpp-cheatsheet","commit_stats":null,"previous_names":["kubgus/cpp-cheatsheet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubgus%2Fcpp-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubgus%2Fcpp-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubgus%2Fcpp-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubgus%2Fcpp-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubgus","download_url":"https://codeload.github.com/kubgus/cpp-cheatsheet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243690147,"owners_count":20331729,"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"],"created_at":"2025-01-21T21:17:27.422Z","updated_at":"2025-12-29T19:36:33.811Z","avatar_url":"https://github.com/kubgus.png","language":"C++","readme":"# C++ Cheatsheet 📜\nA collection of C++ snippets that explain how the language works.\n\n### More fun stuff ⚡\n- [C++ Playground 🎮](https://github.com/kubgus/cpp-playground)\n\n### Made possible by @TheCherno 🚀\nCherno makes programming tutorials focused on C++. The concepts explained in this repo reference his explanations from different videos.\n- [Website](https://thecherno.com/)\n- [YouTube Channel](https://www.youtube.com/@TheCherno)\n- [C++ Playlist](https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb)\n\n#### \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/e/ef/Youtube_logo.png?20220706172052\" alt=\"YouTube logo\" height=\"12\"\u003e First video\n\u003ca href=\"https://www.youtube.com/watch?v=18c3MTX0PK0\u0026list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb\"\u003e\u003cimg src=\"https://i3.ytimg.com/vi/18c3MTX0PK0/maxresdefault.jpg\" alt=\"YouTube Video Thumbnail\" width=\"200\"\u003e\u003c/a\u003e\n\n### Contribution 🤝\nFeel free to contribute your code or point out any issues. We're all human, mistakes in this code are inevitable, but unlikely.\n\n## Built-in data types 🛠️\nhttps://www.tutorialspoint.com/cplusplus/cpp_data_types.htm\n| Data type          | Size     | Range (approx.)                               |\n| :----------------: | :------: | --------------------------------------------- |\n| `bool`               | 1 byte   | 0 and 1                                       |\n| `char`               | 1 byte   | -127 to 127                                   |\n| `unsigned char`      | 1 byte   | 0 to 255                                      |\n| `short (int)`        | 2 bytes  | -32768 to 32767                               |\n| `unsigned short`     | 2 bytes  | 0 to 65535                                    |\n| `int`                | 4 bytes  | -2147483648 to 2147483647                     |\n| `unsigned int`       | 4 bytes  | 0 to 4294967295                               |\n| `long (int)`         | 8 bytes  | -9223372036854775808 to 9223372036854775807   |\n| `unsigned long`      | 8 bytes  | 0 to 18446744073709551615                     |\n| `long long`          | 8 bytes  | -(2^63) to (2^63)-1                           |\n| `unsigned long long` | 8 bytes  | 0 to 18446744073709551615                     |\n| `float`              | 4 bytes  | Floating point numbers                        |\n| `double`             | 8 bytes  | Floating point numbers                        |\n| `long double`        | 12 bytes | Floating point numbers                        |\n| `auto`              | -        | -                                             |\n\n\u003e `auto` is a placeholder for a data type that is automatically deduced by the compiler: [Cherno's video](https://www.youtube.com/watch?v=2vOPEuiGXVo\u0026list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb\u0026index=56)\n\n## Operators 🧮\nhttps://www.tutorialspoint.com/cplusplus/cpp_operators.htm\n| Operator | Description |\n| :------: | ----------- |\n| `sizeof` | Returns the size of a variable |\n| `\u0026` | Returns the address of a variable |\n| `*` | Pointer to a variable |\n| `? :` | Conditional operator |\n| `.` | Member operator |\n| `-\u003e` | Member operator |\n| `++` | Increments the value of a variable |\n| `--` | Decrements the value of a variable |\n| `+` | Adds two operands |\n| `-` | Subtracts two operands |\n| `*` | Multiplies two operands |\n| `/` | Divides two operands |\n| `%` | Modulus operator |\n| `=` | Assigns values from right side operands to left side operand |\n| `+=` | Adds right operand to the left operand and assign the result to left operand |\n| `-=` | Subtracts right operand from the left operand and assign the result to left operand |\n| `*=` | Multiplies right operand with the left operand and assign the result to left operand |\n| `/=` | Divides left operand with the right operand and assign the result to left operand |\n| `%=` | Takes modulus using two operands and assign the result to left operand |\n| `==` | Checks if the values of two operands are equal or not. If yes, then the condition becomes true |\n| `!=` | Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true |\n| `\u003e` | Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true |\n| `\u003c` | Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true |\n| `\u003e=` | Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true |\n| `\u003c=` | Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true |\n| `\u0026\u0026` | Called Logical AND operator. If both the operands are non-zero, then the condition becomes true |\n| `\\|\\|` | Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true |\n| `!` | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make it false |\n\n## Access Specifiers 🔒\n| Specifier | Description |\n| :-------: | ----------- |\n| `public` | Members are accessible from outside the class |\n| `private` | Members cannot be accessed (or viewed) from outside the class |\n| `protected` | Members cannot be accessed from outside the class, however, they can be accessed in inherited classes |\n\n## Other Specifiers 📌\n| Specifier | In this repo | C++ Reference | Description |\n| :-------: | :-----: | :-----------------: | ----------- |\n| `const` | [`const.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/const.cpp) | [Link](https://en.cppreference.com/w/cpp/language/cv) | Makes a variable immutable |\n| `static` | [`static.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/static.cpp) | [Link](https://en.cppreference.com/w/cpp/keyword/static) | Makes a variable or function static |\n| `extern` | [`static.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/static.cpp) | [Link](https://en.cppreference.com/w/cpp/keyword/extern) | Declares a variable that is defined in another translation unit or that is defined externally |\n| `inline` | NULL | [Link](https://en.cppreference.com/w/cpp/language/inline) | Instructs the compiler to insert a copy of the code of a function at the point where the function is called at compile time |\n| `constexpr` | NULL | [Link](https://en.cppreference.com/w/cpp/language/constexpr) | Instructs the compiler to evaluate the value of an expression at compile time |\n| `virtual` | [`virtual.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/virtual.cpp) | [Link](https://en.cppreference.com/w/cpp/language/virtual) | Declares a function that can be overridden in a derived class |\n| `override` | [`virtual.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/virtual.cpp) | [Link](https://en.cppreference.com/w/cpp/language/override) | Specifies that a virtual function overrides another virtual function |\n| `final` | NULL | [Link](https://en.cppreference.com/w/cpp/language/final) | Specifies that a virtual function cannot be overridden in a derived class or that a class cannot be inherited from |\n| `explicit` | [`explicit.cpp`](https://github.com/kubgus/cpp-cheatsheet/blob/main/explicit.cpp) | [Link](https://en.cppreference.com/w/cpp/language/explicit) | Prevents a type to be converted to another type implicitly |\n| `friend` | NULL | [Link](https://en.cppreference.com/w/cpp/language/friend) | Grants a function or another class access to private and protected members of a class |\n\n\u003e `inline` vs `constexpr`: [Explanation](https://stackoverflow.com/questions/7113872/inline-vs-constexpr)\n\n## Stack vs Heap 📚\nhttps://www.youtube.com/watch?v=wJ1L2nSIV1s\u0026list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb\u0026index=54\n|                      | Stack                              | Heap                                |\n| :------------------: | ---------------------------------- | ----------------------------------- |\n| Initialization       | `int a;`                           | `int* a = new int;`                 |\n| Memory Allocation    | `int a[5];`                        | `int* a = new int[5];`              |\n| Access               | `a = 2;`                           | `*a = 2;`                           |\n| Deletion             | Automatically when out of scope    | `delete a;`                         |\n| Size                 | Smaller                            | Larger                              |\n| Stored               | Together in memory                 | Fragmented                          |\n| Allocating           | Costs around 1 CPU instruction     | Costs a lot more                    |\n\n## Casting 🎭\nhttps://www.tutorialspoint.com/cplusplus/cpp_casting_operators.htm\n| Operator | Description |\n| :------: | ----------- |\n| `static_cast` | Checks if the type of the expression is compatible with the target type and converts it if possible. |\n| `reinterpret_cast` | Converts any pointer type to any other pointer type. The operation result is a simple binary copy of the value from one pointer to the other. (type punning) |\n| `const_cast` | Modifies the const, volatile, and __unaligned attributes of the type. (usually used to remove `const`) |\n| `dynamic_cast` | Returns a null pointer of the target type if the conversion is not possible. |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubgus%2Fcpp-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubgus%2Fcpp-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubgus%2Fcpp-cheatsheet/lists"}