https://github.com/mortennobel/cpp-cheatsheet
Introduction
C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language.
C++ is an extension of the C programming language, with added features such as object-oriented programming, classes, and exception handling.
<aside>
💡 C++ builds upon the features of C, and thus, most C programs can be compiled and run with a C++ compiler.
</aside>
C++ offers a great balance of performance, portability, and feature set, making it a versatile and powerful programming language suitable for many applications. With its extensive libraries, active community, and continuous development, C++ is an excellent choice for any software development project.
- Performance: C++ is designed to provide high performance and efficiency. It offers fine-grained control over system resources, making it easier to optimize your software.
- Portability: C++ is supported on different computer architectures and operating systems, allowing you to write portable code that runs on various platforms without making major modifications.
- Object-Oriented Programming: C++ supports object-oriented programming (OOP) - a paradigm that allows you to design programs using classes and objects, leading to better code organization and reusability.
- Support for low-level and high-level programming: C++ allows you to write both low-level code, like memory manipulation, as well as high-level abstractions, like creating classes.
- Extensive Libraries: C++ offers a vast range of libraries and tools, such as the Standard Template Library (STL), Boost, and Qt, among others, that can aid in the development of your projects and make it more efficient.
- Combination with C language: C++ can be combined with C, offering the capabilities of both languages and allowing you to reuse your existing C code. By incorporating C++ features, you can enhance your code and improve its functionality.
- Active Community: C++ has been around for a long time and has a large, active community of users who contribute to the growth of the language, express new ideas, and engage in discussions that help develop the language further. This makes finding solutions to any problems you experience much easier.
C++ is widely used in various applications like game development, system programming, embedded systems, and high-performance computing.
C and C++ are two popular programming languages with some similarities, but they also have key differences.
C
- C is a procedural programming language.
- Focuses on functions and structured programming.
- Does not support objects or classes.
- Memory management is manual, using functions like
malloc
and free
.
- Code reusability is achieved through functions and modular programming.
- High cohesion and low coupling are achieved via structured design.
- Function libraries can be created and included through headers.
- Error handling in C is done primarily through return codes.
- Lacks support for exceptions or any built-in error handling mechanism.
C++
- C++ is both procedural and object-oriented.
- Supports both functions and classes.
- Incorporates different programming paradigms.
- Memory management can be manual (like C) or rely on constructors/destructors and smart pointers.
- Offers better code reusability with classes, inheritance, and polymorphism.
- Code modularity is enhanced through namespaces and well-designed object-oriented hierarchy.
- Offers exception handling, which can be used to handle errors that may occur during program execution.
- Enables catching and handling exceptions with
try
, catch
, and throw
keywords, providing more control over error handling.
While C is simpler and focuses on procedural programming, C++ offers the versatility of using different programming paradigms and improved code organization.
Language Tools
Compilers