Modern C++ • C++20 baseline
Write Your First C++ Program
Use main, standard output, and a return status in a minimal program.
A hosted C++ program begins execution in main. Include the header that declares each standard-library feature rather than relying on another header to include it indirectly. Returning zero from main reports successful completion.
Key points
- Angle-bracket includes name standard headers.
- std:: qualifies names that live in the standard namespace.
Example
#include <iostream>
int main() {
std::cout << "Hello, C++20!\n";
return 0;
}
What to expect
Hello, C++20!
Practice exercise
Change the output to include your name and a second line that describes a program you want to build.
Key idea: A small complete program is a useful first test of the compiler, linker, and runtime.