Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

hello-world-cpp

Hello, World in C++

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Hello, World in C++: the syntax, patterns, and safety habits you need before advancing in C++.

Teams still ship Hello, World in C++ in C++ codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Hello, World in C++ in contexts like: Game engines, trading systems, desktop apps, and performance-critical libraries.

Write C++ in main.cpp with int main(), click Run on server—the dev runner compiles with c++/g++ -std=c++17 -Wall and runs the binary; read template errors in stderr (LEARNING_RUNNER_ENABLED=true). Also include iostream and use std::cout; keep everything in one main.cpp for the sandbox.

When you can explain the previous lesson's ideas without copying starter code.

Every C++ program needs an entry point: main. The simplest program prints a line and returns an exit status to the operating system.

Minimal program

#include <iostream>

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

#include <iostream> pulls in stream I/O. std::cout writes to stdout; return 0; signals success to the shell.

Reading main

  • int main() — playground default entry point
  • int main(int argc, char* argv[]) — receives command-line arguments (covered in systems lessons)
  • Return type int is the process exit code

Important interview questions and answers

  1. Q: Why include iostream?
    A: Declares std::cout, std::cin, and related stream types; without it you get compile errors.
  2. Q: cout vs printf?
    A: std::cout is type-safe and extensible via operator overloading; printf is C-style and requires format strings.

Self-check

  1. Which header declares std::cout?
  2. What return value means success?

Tip: Always #include <iostream> for std::cout—unlike C's stdio.h, streams are type-safe.

Interview prep

Why include iostream?

Declares std::cout, std::cin, and stream types used for I/O.

What does return 0 mean?

Conventionally signals successful program termination to the operating system shell.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • using namespace std?
  • return 0 why?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump