Header Ads Widget

Responsive Advertisement

C++ Hello World

C++ programming language: If you want to learn C language easily you need to start making programs/codes. As you may already know that to develop programs you need a text editor and a compiler to translate a source program into machine code which can be executed directly on a machine.So the best  programming platform for you to start practicing programs are :  For PC - Code blocks, Dev C++ or For Android - turboCdroid.

How to write a hello world in C++ language? 
This could be your first C++ program.But if you have practiced C language programs then it is going to help you a lot. Let's have a look at the program first.

SIMPLE DISPLAYING

#include <iostream.h>  //Start of the program with header files  is must.
#include<conio.h>
void main()                 

{
  cout<<HELLO WORLD";  
//Display function printf() is used.  
  getch();  
// help to come out from output screen.
}

  •  <iostream.h>= It is the library which contains standard input/output streams.
  •  cout = It is library function used to display text on the screen.
  •  getch()=The getch() function is used to catch a character from the keyboard. It is used to holds the output window until hitting any key from the keyboard.
OUTPUT : 

HELLO WORLD
     


DISPLAY using character variables


#include <iostream.h>  //Start of the program

#include<conio.h>

void main()
{
  char a,b.c,d,e,f,g;   
// Declaring variables 

   a = 'H'; // assigning values to the variables.

   b = 'E';

   c = 'L';

   d = 'O' 

   e = 'W';

   f = 'R':

   g = 'D'; // assigning values to the variables.

   cout<< a<< b<<c<<c<< d<e<<<d<< f<< c<<g;  //Displaying the output

  getch();

}

 OUTPUT :

HELLOWORLD            


 DISPLAY using string (a character array).

#include <iostream.h> //Start of the program

#include<conio.h>

void main()
{
  char s1[ ] = "HELLO WORLD\t"; 
  char s2[] = {'H','e','l','l','o','w','o','r','l','d'}; 
//Declaration of variables and assigning value to them.

  cout<< s1<<s2; //Displaying the output.

  getch();

}

Output:

HELLO WORLD        Helloworld      

  • \t = places the cursor 8 steps ahead.


(HINT+NOTE) :
  • If you are using code blocks as your programming platform then it is must for you that after the preprocessor header line statement you need to add a line :
         using namespace std;      //it is used because computer needs to know the code for the cout , cin functionalities. 




Post a Comment

0 Comments