Program to print Hello World in C++|C++ Hello World Program

program to print hello world in c++

Program to print Hello World in C++

While writing programs in C or C++, first use Header Files (Preprocessor). This has to be written because there are some Library Functions in it. To write a program, it is necessary to write Library Functions.

The first header files in the program are #include<iostream.h> this is the input/output stream header file and the second #include<conio.h> is written as the console input/output header file. After that, the main program starts.

In C Programming, the program starts with the main() function, but in C++ Programming, the program has to be started with int main(). The C++ Programming Program has to return an integer value. After that cout is used to print the message output and finally returns 0 to return the value to int main(); writes.

C++ Hello World Program

In C++, before creating a program, we include some pre-defined library files in the header section of the program.

In these files, there are many pre-defined functions that contain the code for a task. To use these functions in a program, we have to include their file (in which they are defined) in the header of the program.

In a program, the syntax for including header files is given below –

#include<filename.h>

It has h, file extension.

cout in C++

The cout statement is used to print a message or result on the monitor screen because this output operation is performed, hence it is also known as an output statement in C++.

cout<<"message";

In this << is called insertion operator.

Example:-

cin>>variable1;
cin>>variable2;

Or

cin>>variable1>>variable2;

In this >> is called insertion operation.

The store value in a variable is called an output statement.

Example:-

cout<<variable1<<variable2;

C++ hello world program

This is a simple program in which we print a message.

The program given below is based on Turbo C++:–

Source code:-

#include<iostream.h>
#include<conio.h>
   { 
     void main()
     cout<<"Hello world";
     getch();

      }

Output:-

Hello world

Explanation:

<iostream.h> and <conio.h> are both header files.

void is a return type, in which main() is a function that is the execution point of a program. Because there is a void type function, so function main() returns any value.

getch() is a function that holds the output.

Things to know

In C++, both the statements (cout, cin) are terminated by semicolon (;).

Both cout and cin are defined under iostream-class, so we include their header file (iostream.h) in the program.

In the cout statement, the message is written in double quotes, whereas in the cin statement, double quotes are not used to read the value of a statement.

To display the value of a variable in the program, double quotes are not used in the exit statement.

If you are in visual studio (C++) it will be something like this –

#include<iostream>
using namespace std;
 int main()
  {
    cout<<"Hello world";
      return 0;

       }

Output:-

Hello world

Previous articleसाइबर सिक्योरिटी सिस्टम क्या है | security system project in c++ in hindi
Next articleinterfacing the os in python|operating system interface in python

LEAVE A REPLY

Please enter your comment!
Please enter your name here