Every C++ program follows a basic structure. Let us look at the parts:
#include <iostream> // 1. Include libraries
using namespace std; // 2. Use the standard namespace
int main() { // 3. Main function — entry point
cout << "Hello!"; // 4. Statement
return 0; // 5. Return value
}
Part
Description
#include <iostream>
Header file for input/output operations
using namespace std;
Avoids writing std:: before every standard name
int main()
Entry point — every program starts here
{ }
Curly braces define a code block
return 0;
Returns 0 to the OS, signalling success
Statements and Semicolons
Every statement in C++ must end with a semicolon (;). Missing semicolons are one of the most common beginner errors.