Turning Learners Into Developers
Codekilla
CODEKILLA
back to course
Lesson 02 / 713%· free preview
Getting Started2/5

C++ Get Started

Install a C++ compiler, set up your editor, and run your first program from scratch.

What is C++?

To start writing C++ code, you need just two things:

  1. A C++ compiler — translates .cpp source into an executable.
  2. A text editor or IDE — VS Code, CLion, Code::Blocks, or even Notepad.
Choose a Compiler
OSRecommended CompilerInstall Command
WindowsMinGW-w64 (GCC)Use the MSYS2 installer
macOSClang (Xcode CLT)xcode-select --install
Linuxg++sudo apt install g++

Verify your install:

bash
g++ --version

You should see something like g++ (GCC) 13.2.0.

Hello World — End to End

Step 1. Create a file hello.cpp:

cpp
#include <iostream>
using namespace std;

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

Step 2. Compile:

bash
g++ hello.cpp -o hello

Step 3. Run:

bash
./hello       # macOS / Linux
hello.exe     # Windows
Hello, Codekilla!
What Just Happened?
  • The compiler read hello.cpp.
  • It translated the C++ into machine instructions for your CPU.
  • It linked in the standard library (so cout works).
  • It produced an executable binary called hello.

You don't need a runtime (like the JVM or Python interpreter) — the binary runs natively.

Useful g++ Flags
FlagPurpose
-o nameSet output filename
-WallShow all warnings (highly recommended)
-std=c++17Use the C++17 standard (or c++20, c++23)
-gInclude debug symbols (for gdb)
-O2Optimise for speed

A safe default for learning:

bash
g++ -std=c++17 -Wall -g hello.cpp -o hello
VS Code Setup (recommended)
  1. Install VS Code.
  2. Add the C/C++ extension by Microsoft.
  3. Add Code Runner (optional, gives you a one-click ▶ Run button).
  4. Open your folder, create hello.cpp, hit ▶ — you're coding.
Online Compiler — Skip Setup

Don't want to install anything? Use Codekilla's online C++ compiler — write code in the browser, click Run, see output. Perfect for learning on the go.

Common Mistakes
  • Compiling but not runningg++ hello.cpp -o hello only creates the binary; you still need ./hello to execute.
  • Wrong filename — Save as hello.cpp (not .c or .txt); .cpp is the standard extension.
  • g++ not found — PATH not set after install. Restart the terminal or add the compiler's bin/ to PATH.
  • Mixing tabs/spaces — Doesn't break C++ (it's not Python), but inconsistent indentation looks awful.
  • Skipping -Wall — You'll miss bugs that the compiler could catch for free.
Interview Questions

Practice Exercises
  1. Install + compile — Set up g++ on your machine and compile hello.cpp. Confirm the binary runs. Hint: check version with g++ --version.
  2. Filename change — Compile with g++ hello.cpp -o greeter and run ./greeter. Hint: name doesn't have to match source.
  3. Add a warning — Add an unused variable like int x; and compile with -Wall. Hint: warning will say "unused variable x".
  4. Print three lines — Modify the program to print 3 lines of your choice and re-run. Hint: 3 cout statements.

Think Like a Programmer: Master your toolchain first. Spending 30 minutes to set up g++ -Wall -std=c++17 saves you from days of confusing bugs later.

AI-powered recap

Quick recap quiz?

We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.

# program

Program

C++
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, Codekilla!" << endl;
    cout << "My first C++ program." << endl;
    return 0;
}
Ready to move on?
// example library
Want more hands-on snippets in C++?
Browse 100 runnable examples · across 10 chapters · short, copy-paste-friendly · grouped by topic
Explore examples
// deep-dive
Go deeper — hand-picked articles
Long-form guides, shortcuts, and mental models that won't fit in a single lesson.
Open Blog
// feedback.matters()
Did this lesson help you?