C++ chapters

Chapter 3 of 17

C++ Syntax

Try this in our C++ Compiler →

Statements and structure

A C++ program is a list of statements that the computer executes one after another. The language has strict rules — called syntax — about how those statements must be written. Get the syntax slightly wrong and the program will refuse to run. The good news is the rules are small and consistent: once you have learned the basic shape of a statement you can read almost any C++ program.

Comments

Comments are notes for humans that the computer ignores. Use them generously to explain why your code does something, not what it does. Future-you (and your teammates) will thank you.

```cpp
#include <iostream>

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

Case sensitivity and whitespace

C++ is case sensitive — Total and total are two different names. Indentation makes code readable; in some languages it is purely cosmetic and in others (like Python) it is part of the syntax. Always indent the body of a block.

Try it yourself

C++ Compiler
Output
Code runs on the Play with Coding execution engine — your code is saved locally for next time.