C Program to Print Hello World

In programming world, learning programming language starts with writing simple program that prints Hello, World!. It's kinda convention!! You can print anything you want. In this program we are going to learn how to print some message in C programming language.

To display or print something on screen you need to know some command or function or instruction that does this job. In C programming, to display something on screen, printf() is used.

And in C we call this function because it does some specific job. When something comes along with parantheses i.e. ( ) in C programming language then most of the times it is function. Quick note there :) !!

Program to Display "Hello, World!"


#include<stdio.h>
#include<conio.h>

int main()
{
	clrscr(); /* Clears Screen */
	printf("Hello, World!");
	getch();  /* Holds the output */
	return 0;
}

--------------------------------
				OR
--------------------------------
#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr(); /* Clears Screen */
	printf("Hello, World!");
	getch();  /* Holds the output */
}

Output of above program :

	
Hello, World!	

"Hello, World!" Program Explanation (Step Wise)

  1. In C programming smallest possible program that does nothing is :
    
    int main()
    {
    	// Here we write something
    	return 0;	
    }
    
    OR
    
    void main()
    {
    	// Here we write something		
    }
    
    So, In C main() is unique function which is already defined in C language. Execution of C program starts from main() function so we must write this function in above format.
    In the above smallest program we have used //. In C language, anything starting from // and anything written within /* and */ are known as Comments. Comments are those peace of information which are totally neglected by compiler.
    So, // Here we write something is comment.
  2. If you are using compiler other than Turbo C you may not require clrscr() and getch() and you do not require to include conio.h
  3. So what are we doing inside main() function? First, we are executing clrscr(); which clears the output window (if there is anything in output window that will be erased).
  4. Second, we are executing printf("Hello, World!");which displays the text "Hello, World!" to the output screen. Here, header file stdio.h is included because function printf() is defined in stdio.h header file.
  5. Third or at last, we are executing getch(); is executed which holds the ouput screen untill user presses something on keyboard.

Congratulations! you have learned your first program in C language successfully.

Never stop learning! Now check this example: C Program to Add Two Numbers