Hello world in C/C++

Hello world in C/C++

Whenever we start learning new programming language this is the basic thing we try to learn at the beginning i.e. how to print hello world!. In this post we are going to see how to print “Hello world in C/C++”.

//Hello world! in c
#include<stdio.h>
#include<conio.h>
int main()
{
   clrscr();
   printf("Hello world!");
   return 0;
}
//Hello world! in c++
#include<iostream.h>
#include<conio.h>
int main()
{
   clrscr();
   cout<<"Hello world!";
   return 0;
}

In various IDE’s like vs code #include<iostream.h> is not recognized. Thus we have to use #include<iostream> and using namespace std; It is shown below.

//Hello world! in c++
#include<iostream>
using namespace std;
int main()
{
   cout<<"Hello world!";
   return 0;
}

Output :-

Hello world! in c/c++

Program Parts :-

#include is a pre-processor directive. It is use to include header files.
stdio/iostream is header file which has certain commands that c/c++ supports. E.g. return, main, etc.
conio is a header file which is use to include commands like clrscr(), getch() in the code.
.h is an extension for header file.
int is data type. It indicates that the program returns a value.
main() is main function that indicates the compiler that the user written programs starts from here.
clrscr() is function to clear the output screen. Due to clrscr, every time new output is shown on new screen.
print/cout is the keyword use to print a message.
return statement is use to return a value. If any error occurs the program will return 0.

Explanation :-

Program is simply going to print a Hello world!. The program will check the header files and then it will enter the main function. In main function it will find print/cout function which will print Hello world!.

Conclusion :-

So this is how we print Hello world! in C/C++. There are many methods we can use to print a message. Tell us in comment section below about your logics or which other program you want us to upload.

For more such programs visit ErrorFreeProgram.

1 COMMENT

Leave a Reply

Your email address will not be published. Required fields are marked *