C++ Basics · Chapter 1

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.

By Arj Updated July 2026 10 min read No prior experience needed
What you'll learn
  • 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.

You are not choosing a language forever
The concepts you learn here, variables, loops, functions, logic, transfer almost directly to any other language you pick up afterward. Learning C++ first tends to make learning Python, Java, or JavaScript later noticeably easier, since you already understand what is happening underneath the more forgiving syntax those languages offer.

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++.

C++ compiler

Translates your human-readable code into a program the computer can execute. Common choices are GCC on Linux, MinGW on Windows, and Clang on macOS.

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:

Online compilers versus local setup
Online compilers are the fastest way to try the examples in this chapter with zero setup, and they are perfectly fine for learning. Once you start building anything larger than a single file, though, installing a real compiler and IDE locally gives you far better tools: debugging, autocomplete, and the ability to work offline.

4Your first C++ program: Hello, World!

Every programming tradition starts here. Let's write the most basic program possible in C++.

hello.cpp
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
What each line does
  • #include <iostream> tells the compiler to include the standard input and output stream library, which is what gives you access to std::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::cout is used to print output to the screen, the name stands for "character output".
  • std::endl ends 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.

terminal
g++ hello.cpp -o hello
./hello
OutputHello, World!

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.

cpp
// 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.

cpp
int age = 20;
double weight = 65.5;
char grade = 'A';
bool passed = true;
TypeStoresExample
intWhole numbers20
doubleDecimal numbers65.5
charA single character'A'
boolTrue or falsetrue

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

cpp
#include <iostream>

int main() {
    int age = 20;
    std::cout << "Age: " << age << std::endl;
    return 0;
}
OutputAge: 20

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

Try it yourself

Write a program that prints exactly the following two lines to the screen:

Target outputWelcome to Painless Programming! C++ is powerful.

Hint: use std::cout twice in a row, or use \n inside a single string to insert a line break.

8Quiz yourself

C++ Basics Quiz
Question 1 of 5

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
Coming up next
Variables, Data Types & Expressions
Go deeper into how C++ stores data, including strings, input handling, and how computers actually represent numbers.
Continue to Chapter 2

Stop wrestling with confusion.

Join thousands of students mastering Computer Science without the academic jargon.

From syntax to systems. We break down the hardest ideas in computer science so you can actually build things.

© 2026 Painless Programming. Built for students.
Scroll to Top