C++ Basics
Write and run a first program.
On this page
The concept
A C++ program begins in main. Include iostream to write to standard output with cout. The line using namespace std; lets you write cout instead of std::cout.
Code example
#include <iostream>
using namespace std;
int main() {
cout << "Hello Programonic\n";
}Hello Programonic
With the std:: prefix
The standard library lives in the namespace std. The program above uses using namespace std; so that names such as cout can be written without a prefix, which is the simplest way to start. You can also leave the using line out and write std::cout instead. Both programs do exactly the same thing. The std:: prefix is the safer habit in larger programs and header files, because it avoids name clashes.
#include <iostream>
int main() {
std::cout << "Hello Programonic\n";
}Hello Programonic
Follow the code
Open the walkthrough to inspect the example one step at a time.
Show guided walkthrough
#include <iostream>using namespace std; int main() { cout << "Hello Programonic\n";}Follow the example
Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.
View the complete dry-run table
| Step / line | What happens | State after step | Output so far |
|---|---|---|---|
| Program execution enters main. | — | — | |
| Write the string and newline to standard output. | — | Hello Programonic |
Behind the scenes
How C++ processes this code
The C++ compiler produces a native executable. Execution enters main, where objects and function calls perform the work.