Introduction to Programming & C++ Basics
What programming actually is, why C++ is still one of the most powerful languages to learn it with, and how to write, compile, and run your very first program.
- Understand what programming is and why it matters
- Know what C++ is and where it is actually used
- Set up your development environment
- Write, compile, and run your first C++ program
- Understand basic syntax: comments, variables, and console output
1What is programming
Programming is the process of writing instructions that a computer can execute. Those instructions are written in a programming language, a formal set of rules a computer can parse and act on. Think of it as telling the computer exactly what to do, one precise step at a time, since computers have no ability to guess your intent the way another person might.
Programming is what makes it possible to:
- Build applications, games, and websites, the software people interact with every day
- Automate repetitive tasks, so a computer does in seconds what would take a person hours
- Control hardware like robots, sensors, and embedded devices
- Solve real-world problems with logic and precision, from routing delivery trucks to modeling climate data
2Why learn C++
C++ is a general-purpose programming language known for its speed and control over hardware, and despite being decades old, it remains one of the most widely used languages in performance-critical software today. You will find it running underneath:
- Game development, including engines like Unreal Engine
- Operating systems and compilers, where speed and low-level memory control matter most
- Embedded systems and hardware control, from microcontrollers to industrial equipment
- High-performance applications like trading systems, simulations, and real-time rendering
- Competitive programming and coding interviews, where C++ is a common default choice
Beyond where it is used, C++ is also simply a great language to learn the fundamentals of programming with: variables, loops, conditionals, functions, memory, and object-oriented programming all show up clearly and explicitly, without a lot of hidden behavior obscuring what is actually happening.
3Setting up your environment
To start writing and running C++ programs, you need exactly two things: somewhere to write code, and something to turn that code into a program the computer can run.
Text editor or IDE
Where you actually write your code. Options include Visual Studio Code, Code::Blocks, CLion, or even a plain text editor like Notepad++.
If you are just starting out, the easiest path is an IDE that bundles both together, Code::Blocks works out of the box, and Visual Studio Code with the official C/C++ extension is another excellent, more modern option.
If you would rather skip local setup entirely for now, an online compiler lets you write and run C++ directly in the browser:
4Your first C++ program: Hello, World!
Every programming tradition starts here. Let's write the most basic program possible in C++.
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
#include <iostream>tells the compiler to include the standard input and output stream library, which is what gives you access tostd::cout.int main()is the starting point of every C++ program. Execution always begins here, regardless of how many other functions exist elsewhere in your code.std::coutis used to print output to the screen, the name stands for "character output".std::endlends the current line, similar to pressing Enter, and also flushes the output buffer.return 0;ends the program and signals to the operating system that it ran successfully. A non-zero return value conventionally signals that something went wrong.
5Compiling and running
If you are using an IDE, this step is usually a single click, look for a "Run" or "Build and Run" button.
If you are working from a terminal with g++ directly, it is a two-step process: compile, then execute.
g++ hello.cpp -o hello ./hello
The first line compiles hello.cpp into an executable file named hello (the -o hello flag names the output file). The second line runs that freshly built executable. On Windows, the equivalent command to run it is usually hello.exe or .\hello.exe instead of ./hello.
6C++ basics, line by line
Comments
Comments are notes for humans reading the code. The compiler ignores them entirely, they exist purely to explain your reasoning to future readers, including your future self.
// This is a single-line comment /* This is a multi-line comment. It spans multiple lines. */
Variables
Variables store data, and unlike some other languages, every C++ variable must declare its type up front. The type tells the compiler how much memory to reserve and what kind of operations are valid on that value.
int age = 20; double weight = 65.5; char grade = 'A'; bool passed = true;
| Type | Stores | Example |
|---|---|---|
int | Whole numbers | 20 |
double | Decimal numbers | 65.5 |
char | A single character | 'A' |
bool | True or false | true |
This next chapter goes much deeper into data types, so for now the important habit is simply this: every variable needs a type, chosen based on what kind of value it will hold.
Printing variables
#include <iostream> int main() { int age = 20; std::cout << "Age: " << age << std::endl; return 0; }
The << operator streams values to cout one after another, so you can chain a string, a variable, another string, and so on, all in a single statement.
7Exercise: write your own program
Write a program that prints exactly the following two lines to the screen:
Hint: use std::cout twice in a row, or use \n inside a single string to insert a line break.
8Quiz yourself
9Summary
- What programming actually is, and why it matters
- Why C++ is still a relevant and powerful language to learn
- How to set up your development environment
- How to write, compile, and run your first program
- The basics of comments, variables, and console output
