C++
C++ is programming language created in 1985 by Bjarne Stroustrup.
C++ is based on the C programming language. OOP in C++ was inspired by the Simula67 programming language. Almost all C programs are valid C++ programs.
The name of the C++ programming language is related to the incremental operator "++" and was created by Rick Mascitti in Summer 1983 and was first used in December 1983.
The C++ predecessor is "C with Classes", which is an extension of the C programming language created by Bjarne Stroustup in 1979.
- "C with Classes" introduced object-oriented programming (OOP).
- "C with Classes" maintained the efficiency of C.
Advantages:
- powerful
- high-performance
- it combines the efficiency of low-level programming with the flexibility of high-level abstractions.
- Procedural - emphasizes algorithms, for big projects
- Object-oriented - emphasizes data, for big projects
- Generic - emphasizes algorithms, for small tasks like sorting or linked lists
- Functional
- Whether you're developing high-performance applications, working on system-level programming, or building scalable software, C++ provides the tools and flexibility needed for success.
- Object-Oriented Programming (OOP): Supports classes, inheritance, polymorphism, and encapsulation.
- Templates & Generic Programming: Enables code reusability through function and class templates.
- Memory Management: Provides both automatic and manual memory control via new, delete, and smart pointers.
- Standard Template Library (STL): Includes data structures, algorithms, and iterators for efficient programming.
- Multithreading Support: Offers thread management features for concurrent programming.
- Low-Level Manipulation: Allows direct interaction with hardware, making it suitable for system-level programming.
- High Performance: Optimized for speed and resource management, making it ideal for performance-critical applications.
- Game Development: Used in game engines like Unreal Engine.
- Operating Systems: Many operating systems, including parts of Windows and Linux, are built with C++.
- Embedded Systems: Used in automotive software, IoT devices, and real-time systems.
- Finance & Trading Systems: High-frequency trading platforms rely on C++ for low-latency execution.
- Scientific Computing: Used in applications like MATLAB, CERN software, and physics simulations.
Comparison of C++ and C
The following are examples of additional features in C++ compared to C:- Classes
- Objects
- Inheritance
- Polymorphism
- Virtual functions
- Runtime type identification (RTTI)
- Function overloading
- Reference variables
- Generic programming via the Standard Template Library (STL
- Exceptions
- Namespaces
How to create a C++ program
creating the C++ source code (text files), compiling to object files, linking object files to an executable version of the program.Other
How to manage memory automatically: Boehm-Demers-Weiser Garbage CollectorFunctions
C++ program consists of functions. Function consists of statements. Each statement must end with the semicolon character. Prototype vs implementation.Function main()
Function main() is the entrypoint of an C++ application.
Variants:- int main() {return 0;}
- void main() {return 0;}
- void main(void) {return 0;}
- int main(void) {return 0;}
Console
How to delay program and wait for the press of the key Enter: cin.get();Printing text to console: cout << "some text"; //operator overloading: <<
Reading text from console: cin >> carrots;
How to print end line: "\n" or std::endl
Comments
One line: // commentMulti line: /* comment */
Preprocessor directives
#include <iostream>
Includes file iostream#define INT_MAX 32767
Replaces all INT_MAX occurences by 32767Importing namespaces
using namespace std;using std::count;
C++ statement
Each C++ statement must be ended with the semicolon character ;Declaration (statement type)
This allocates memory.Example: int carrots;
Assignment (statement type)
Example: carrots 15;Initialization (statement type)
int carrots 15;//or
int carrots (15);
Key words
return, void, int, const And othersVariable
Variable is named location in the memory with its type definition.You can get the location in the memory with the & operator.
Data types
Void
Empty set of values, cannot be used as the type of variable.Integral
short: at least 16 bitsint: at least the same size as short (since -32768 until 32 767)
long: at least 32 bits, at least the same size as int
long long (since C++ 99): at least 64 bits, at least the same size as long
unsigned: unsigned short, unsigned int, unsigned long, unsigned long long
Octal: starts with 0
Hexadecimal: starts with 0x or 0X
char
wchar_t
bool
Floating-point
Combined data types
Operators
sizeof
Class
Class is user defined typeC++ Decompilers
Ghidra
Books: https://www.amazon.com/Ghidra-Book-Definitive-Guide/dp/1718501021IDA
https://hex-rays.com/decompilerC++ Disassemblers
Objdump
How to convert a x86 exe file to the Assembly language
objdump -D -M intel your_file.exe > output.asm
-D means to disassembly the whole file
-M intel sets the format of the assembly to Intel
Books
- The Design and Evolution of C++”