C++ Basic Syntax


Go to main Page

Basic syntax in C++

  1. You need to compose header record iostream with #include
  2. Then we have to write using namespace std
  3. Then you have to start the main part where coding starts.
Let us have a look on basic syntax

#include <iostream>
using namespace std;

// main() is where program starts.
int main() {
   cout << "Hello World"; // prints Hello World
   return 0;
}

Output
Hello World

Explaination of above code

Compile and run program

First, you need to download and install Dev C++.

Then you need to open a new file by ctrl+n.

Write code and then press f11.

Your program will compile and run.

C++ semicolons

semicolons are necessary and an important part of C++ Programming.

Without semicolons, it will show you an error.

Program to print the name of your Country

#include <iostream>
using namespace std;

// main() is where program starts.
int main() {
   cout << "Pakistan"; // prints Hello World
   return 0;
}

Output
Pakistan

Basic programs to practice

  1. Write a C++ Program to Print Your School name?
  2. Write a C++ Program to display your address in output?
  3. Write a C++ Program to print your name and your friend name?