Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

C++ Program Structure · Lesson 13 of 25

C++ Syntax Basics

A free lesson from Swipe Coding · C++, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Time to pull together everything you have learned about the rules. 📋

You now know about the preprocessor, functions, the main() function, statements, and code blocks. Let's summarize a few basic syntax rules that apply to every C++ program.

std::cout << "Hello!"; // correct
Std::Cout << "Hello!"; // Error! C++ is case-sensitive
C++ is "case-sensitive" — capitalization matters. "cout" and "Cout" are two completely different names as far as C++ is concerned.
🤖
Case matters everywhere in C++ — no exceptions. 🔠

This applies to everything in C++: function names, variable names, keywords like "int" or "return". A single letter with the wrong capitalization leads to a compiler error.

Another fixed rule: every #include directive and every statement plays a specific role, and the pieces must appear in a sensible order — for example, you must #include <iostream> before you can use std::cout, since that's where std::cout is declared.

#include <iostream>

int main() {
    std::cout << "Hello, C++!";
    return 0;
}
The #include line must come before std::cout is used — the compiler reads your file from top to bottom.
True or false

C++ is case-sensitive (for example, "cout" and "Cout" are different).

Indentation — spaces at the start of a line that visually shift nested blocks inward — is not required by the compiler. C++ compiles code without any indentation just fine. Still, you should always indent your code cleanly, because it makes nested blocks far easier for people to read.

int main() {
std::cout << "Hello, C++!";
return 0;
}
This code compiles just fine — it's simply much harder to read without indentation than the indented version above.
Quick check

Which statement about indentation in C++ is correct?

🤖
You now have the complete rulebook for any C++ program. 📖

In summary, every C++ program follows these rules: any needed #include directives come first, execution starts in the main() function, every statement ends with a semicolon, related statements sit inside a block of curly braces, and C++ is case-sensitive throughout.

Fill in the blank

To use std::cout for printing text, you must first ____ the iostream header.

Chapter quiz

C++ Program Structure

10 questions · pass with 60% — just like in the app.

Quick check

What is a function in C++?

Fill in the blank

A function that does not return any value uses the return type ____.

True or false

Every C++ program must have exactly one main() function.

Quick check

What does "return 0;" at the end of main() typically signal?

Fill in the blank

Execution of every C++ program begins inside the ____ function.

Quick check

Which character marks the end of a statement in C++?

True or false

C++ executes a program's statements from top to bottom, in order.

Quick check

What are curly braces { } used for in C++?

Fill in the blank

A block that sits entirely within another block is said to be ____ inside it.

True or false

C++ is case-sensitive, so "cout" and "Cout" are treated as different names.

Keep your streak going in Swipe Coding

Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →