CurriculumIntroduction to C++
Introduction to C++
C++ is a high-performance, compiled, statically typed language. Designed by Bjarne Stroustrup in 1979 as an extension of C, it provides low-level memory manipulation alongside high-level abstractions like Object-Oriented Programming (OOP). Let's break down C++ basics piece by piece, starting from a basic program to variables and basic math.
011. Your First C++ Program
Every C++ program starts its execution in the `main()` function. We use `#include ` to bring in the library that lets us print text to the screen using `std::cout` (Character OUTput).
main.cpp
Terminal
Waiting for execution...
Visualizer
Source
.cpp
Preprocessor
#includes
Compiler
Assembly
Assembler
Object code
Linker
Links libs
Executable
a.out
Run the code to animate the pipeline.
022. Variables and Types
C++ is statically typed. This means you must declare the type of a variable before you can use it. The compiler needs to know exactly how much memory to set aside.
Here we declare an integer (`int`), a floating-point number (`double`), and a boolean (`bool`).
main.cpp
Terminal
Waiting for execution...
Visualizer
Click Run to see memory state
033. Basic Arithmetic
C++ supports all standard arithmetic operations. However, integer division acts differently than you might expect coming from languages like Python or JavaScript. `5 / 2` yields `2`, not `2.5`, because the result is truncated to fit in an `int`.
main.cpp
Terminal
Waiting for execution...
Visualizer
Click Run to see memory state
044. Control Flow (If / Else)
To make your programs smart, you use control flow. The `if` statement allows you to execute code conditionally.
Try changing the `score` variable to `40` and run the code again to see how the execution path changes.
Try changing the `score` variable to `40` and run the code again to see how the execution path changes.
main.cpp
Terminal
Waiting for execution...
055. Loops (For and While)
Loops allow you to execute a block of code multiple times. A `for` loop is typically used when you know exactly how many times you want to loop. A `while` loop runs as long as a condition is true.
Notice the `i++` syntax, which is where C++ gets its name (C incremented!).
Notice the `i++` syntax, which is where C++ gets its name (C incremented!).
main.cpp
Terminal
Waiting for execution...
AI Tutor
C++ powers the world's most critical systems: operating systems, game engines, high-frequency trading platforms, and web browsers.