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
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
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;
}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;
}Which statement about indentation in C++ is correct?
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.
To use std::cout for printing text, you must first ____ the iostream header.
C++ Program Structure
10 questions · pass with 60% — just like in the app.
What is a function in C++?
A function that does not return any value uses the return type ____.
Every C++ program must have exactly one main() function.
What does "return 0;" at the end of main() typically signal?
Execution of every C++ program begins inside the ____ function.
Which character marks the end of a statement in C++?
C++ executes a program's statements from top to bottom, in order.
What are curly braces { } used for in C++?
A block that sits entirely within another block is said to be ____ inside it.
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 →