C++ Syntax
C++ statements end with a semicolon `;`, and blocks of code are grouped using curly braces `{ }`. Unlike Python, indentation is only for readability — it has no effect on how code runs.
C++ is case-sensitive, so `Value` and `value` are different identifiers. Whitespace between tokens is generally ignored by the compiler.
Statements and semicolons
Forgetting a semicolon is one of the most common beginner errors and causes a compile error. Each statement — a declaration, assignment, or function call — needs one.
Blocks with braces
Curly braces `{}` group statements into a block, used for functions, loops, conditionals and classes. Braces can be nested to any depth.
#include <iostream>
int main() {
int x = 5;
if (x > 0) {
std::cout << "positive";
}
}positiveThe if-block is grouped with braces; each statement ends in a semicolon.
Key points
- Every statement ends with a semicolon.
- Curly braces {} define code blocks.
- C++ is case-sensitive.
- Indentation is for humans, not the compiler.
