🧱 Section 1 · Foundations 🟢 Beginner MODULE 01

Introduction to C++ & Your First Program

⏱️ 22 min read
📖 Theory + Code
🧩 5 Quiz Questions
🏗️ 1 Challenge
Your progress in Section 120%
🎯 What you'll learn: What C++ actually is, where it's used in the real world, how the "compile then run" model works (and how it's different from an interpreted language like Python), how to install a compiler, and how to write, compile, and run your very first C++ program.

What Is C++?

C++ is a compiled, statically-typed, general-purpose programming language. It was created by Bjarne Stroustrup starting in 1979 at Bell Labs, originally as an extension of the C language called "C with Classes." The name was changed to C++ in 1983 — the ++ is a nod to C's own increment operator, meaning "one step beyond C."

C++ gives you two things that many modern languages trade away for convenience: direct control over memory and hardware, and compiled performance close to the metal. That combination is exactly why it's still the language of choice whenever raw speed and predictable resource usage matter.

💡
"C with Classes" — where OOP met C's speed
C already existed as a fast, low-level systems language. Stroustrup wanted C's performance plus the organizational tools of object-oriented programming — classes, encapsulation, inheritance. C++ is the result: C's speed and control, with modern language features layered on top.
🧑‍💻
Created: 1979–1985
By Bjarne Stroustrup at Bell Labs. First commercial release in 1985.
⚙️
Compiled Language
Source code is translated into native machine code by a compiler before it ever runs.
🔒
Statically Typed
Every variable's type is fixed and checked at compile time — many bugs are caught before the program runs.
📐
ISO Standardized
C++ evolves through numbered ISO standards: C++11, C++14, C++17, C++20, C++23.

Where C++ Is Used

C++ shows up wherever a program needs to run fast, use memory efficiently, and talk closely to hardware or an operating system. That's a wide net — from the engine rendering a video game frame to the firmware inside a microcontroller.

🎮
Game Engines
Unreal Engine and most major AAA engines are written in C++ for real-time performance.
🖥️
Operating Systems
Large parts of Windows, and components of Linux and macOS, rely on C/C++.
🔌
Embedded Systems
Microcontrollers, IoT devices, and firmware where memory is tight and timing matters.
🏆
Competitive Programming
The STL's speed and predictable execution time make C++ a default choice in programming contests.
📊
High-Performance Computing
Scientific simulation, real-time trading systems, and rendering pipelines that need every microsecond.
🗄️
Databases & Runtimes
Database engines and language runtimes are frequently built in C++ for speed and control.
Why performance-critical software keeps choosing C++
C++ doesn't have a garbage collector pausing your program to clean up memory, and it doesn't add an interpreter layer between your code and the CPU. You manage memory directly (or via lightweight abstractions), so behavior — and timing — stays predictable. That predictability is exactly what a game engine's frame budget or a trading system's latency budget needs.

Compiled vs. Interpreted — C++ vs. Python

If you've come from BitWithBite's Python course, this is the biggest mental shift you'll make. Python is interpreted — the Python interpreter reads your .py file and executes it line by line, on the spot. C++ is compiled — a separate program (the compiler) translates your entire .cpp file into a standalone machine-code executable before anything runs.

1
You write source code
A text file with a .cpp extension containing human-readable C++ code.
2
The compiler translates it
A compiler (like g++ or clang++) checks your syntax and types, then translates the whole file into native machine code — an executable file.
3
You run the executable
The resulting program runs directly on your CPU — no interpreter needed at runtime, which is why compiled programs tend to start and run faster.
⚠️
The trade-off
Compiling adds an extra step before you can see your program run, and compiler error messages take some getting used to. In exchange, you get a fast, standalone executable and a huge class of errors caught before the program ever runs — instead of crashing mid-execution like an interpreted script might.

Installing a C++ Compiler

To turn C++ source code into a runnable program, you need a compiler. The two most common ones are g++ (part of the GNU Compiler Collection) and clang++ (the LLVM project's compiler). Either is a fine choice for this course.

🪟 Windows

1
Install MinGW-w64 or use WSL
MinGW-w64 gives you g++ directly on Windows. Alternatively, install the Windows Subsystem for Linux (WSL) and use a Linux distribution's package manager.
2
Add it to PATH
Whichever route you pick, make sure the compiler's folder is added to your system PATH so you can call it from any terminal.
3
Verify the installation
Open a terminal and type g++ --version. You should see version information printed back.

🍎 macOS

1
Install Xcode Command Line Tools
Open Terminal and run xcode-select --install. This installs Apple's Clang compiler.
2
Verify the installation
Run clang++ --version in Terminal to confirm it's ready.

🐧 Linux

Terminal — Ubuntu/Debian
BASH
# Update package list
sudo apt update

# Install the GNU C++ compiler
sudo apt install g++

# Verify installation
g++ --version

🌐 No installation? Use an online compiler

If you just want to try code snippets without installing anything yet, any browser-based C++ compiler works fine for following along with this course — you type code, click run, and see output immediately. You'll still want a real local compiler once you start building larger programs.

💻
Recommended editor: VS Code
Visual Studio Code with the official "C/C++" extension (by Microsoft) gives you syntax highlighting, IntelliSense, and integrated debugging. It's free and works on Windows, macOS, and Linux.

Your First C++ Program — Hello, World!

Every C++ program starts life as a .cpp text file. Let's write the classic first program and then compile and run it.

hello.cpp — Your First C++ File
C++
// hello.cpp
// My first C++ program

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Line by line

1
#include <iostream>
A preprocessor directive that pulls in the input/output stream library, which is where std::cout (console output) lives. Without this line, the compiler has no idea what cout means.
2
int main() { ... }
Every C++ program needs exactly one main function — it's the entry point. Execution always starts at the first line inside main's curly braces. The int means main will hand back a whole number when it finishes.
3
std::cout << "Hello, World!" << std::endl;
std::cout is the standard output stream. The << operator "inserts" values into that stream — here, the text "Hello, World!", followed by std::endl, which prints a newline and flushes the output.
4
return 0;
Ends main and hands the value 0 back to the operating system. By convention, 0 means "the program finished successfully"; any non-zero value signals an error occurred.
📝
What is std::?
std is the standard namespace — the container that holds every piece of the C++ Standard Library, including cout, cin, string, and vector. Writing std::cout tells the compiler exactly which cout you mean, avoiding naming clashes with your own code.

Compiling and running hello.cpp

Save the file, open a terminal in the same folder, and run these two commands:

Terminal
BASH
# Step 1: compile hello.cpp into an executable named "hello"
g++ hello.cpp -o hello

# Step 2: run the executable
./hello        # macOS / Linux
hello.exe       # Windows

# Output:
# Hello, World!
⚠️
If the compiler complains
A missing semicolon, mismatched brace, or missing #include will stop compilation with an error message pointing at a line number. This is normal — reading compiler errors is a skill you'll build quickly. No executable is produced until the code compiles cleanly.

A Second Program — Reinforcing Compile & Run

Let's extend the pattern: print a few lines, then do a tiny calculation and print its result too.

welcome.cpp — Multiple Lines + a Calculation
C++
// welcome.cpp
// Prints a short welcome, then adds two numbers

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    std::cout << "Welcome to C++." << std::endl;

    int a = 7;
    int b = 5;
    std::cout << "7 + 5 = " << (a + b) << std::endl;

    return 0;
}

Compiling this works exactly the same way: g++ welcome.cpp -o welcome, then ./welcome. The output prints three lines — the two greetings, then 7 + 5 = 12. Notice that a and b are declared with a type (int) before they're used — you'll dig deeper into this in Lesson 2.

🔁
Recompile after every change
Unlike Python, editing a .cpp file does nothing to an executable you already built. Every time you change the source, you must re-run the compile step before your changes show up when you execute the program again.

Lesson Summary

Let's recap everything you learned in this lesson:

C++ is a compiled, statically-typed language created by Bjarne Stroustrup as an extension of C.
C++ is widely used in game engines, operating systems, embedded systems, competitive programming, and high-performance computing.
C++ is compiled — your whole source file is translated into machine code before it runs, unlike Python's interpreted, line-by-line model.
You need a compiler — g++ or clang++ — installed and on your PATH before you can build programs.
#include <iostream>, int main(), std::cout <<, and return 0; are the four pillars of a minimal C++ program.
Compile with g++ file.cpp -o program, then run the resulting executable directly.
🧩 Knowledge Check — Lesson 1
Answer all 5 questions to test your understanding. Instant feedback on every answer.
1. Who created C++?
2. What kind of language is C++?
3. Which header must you include to use std::cout?
4. What does return 0; at the end of main() signal?
5. Before a C++ program can run, what must happen first?
💪
Coding Challenge — Lesson 1
Apply what you learned · Beginner Level

Now it's your turn to write real code. Compile and run it with g++ or an online compiler.

Challenge: Print Your Name & Bio 🪪

Write a program called about_me.cpp that prints your name on the first line, and a short 3-line bio below it — for example, where you're from, what you're learning, and a goal. Something like:

Ahmed Khan
I'm learning C++ on BitWithBite.
I'm from Pakistan.
My goal is to build fast, efficient software.

Rules: Use only std::cout statements inside int main(). Include #include <iostream> at the top and end with return 0;. Add at least one comment explaining what the program does.
💡 Show hints if you're stuck
  • Each line needs its own std::cout << "..." << std::endl; statement
  • Don't forget the semicolon ; at the end of every statement
  • Compile with g++ about_me.cpp -o about_me, then run ./about_me
  • Start your file with a comment: // About Me — my first C++ challenge
Finished this lesson?
Mark it complete to track your progress.
🎉

Lesson 1 Complete!

You've compiled and run your first C++ program. 25 more lessons stand between you and true C++ mastery — next up: variables, types, and operators.

Module 01 of 26 Section 1 — C++ Foundations