Writing First Program

Writing your first C++ program is the first step toward learning programming. A simple program helps you understand the basic structure of C++ and how code is executed.

Basic Structure of a C++ Program

A C++ program usually contains:

  • Header files
  • Main function
  • Statements
  • Output commands

First C++ Program

#include <iostream>
using namespace std;

int main() {
cout << "Hello, World!";
return 0;
}

Understanding the Program

#include <iostream>

This line includes the input and output library in the program.

#include <iostream>

It allows you to use:

  • cout
  • cin
  • endl

using namespace std;

This statement allows you to use standard C++ features without writing std:: repeatedly.

using namespace std;

main() Function

The main() function is the starting point of every C++ program.

int main() {
}

Program execution begins from here.

cout Statement

cout is used to display output on the screen.

cout << "Hello, World!";

return 0;

This statement ends the program successfully.

return 0;

Output of Program

Hello, World!

Steps to Run the Program

  1. Open your IDE or code editor
  2. Create a new C++ file
  3. Write the code
  4. Save the file with .cpp extension
  5. Compile the program
  6. Run the program

Important Points

  • Every C++ program must have a main() function
  • Statements usually end with semicolon ;
  • C++ is case-sensitive
  • Curly braces {} define blocks of code

Why Your First Program is Important

Your first program helps you:

  • Understand program structure
  • Learn compilation and execution
  • Practice syntax basics
  • Build confidence in coding

Conclusion

Writing the first C++ program is the beginning of your programming journey. The “Hello, World!” program introduces the basic structure of C++ and helps you understand how programs are written, compiled, and executed.

Home » C++ Fundamentals (Beginner Level) > Introduction to C++ > Writing First Program