Tuesday 3 March 2015

Printing Hello World In C Using Printf Statement




Hay!
In this post we will teach you the first program that every new learner of C language should execute.
We will print "Hello World". For this we will use printf statement which is a library function whose definition is in the stdio.h library file. So lets start.

Syntax:

printf("Any Word,letter or phrase");

now lets try a program:

Program:





#include<stdio.h>
#include<conio.h>
void main(void)
{
printf("Hello World");
getch();
}

in this program i have used one new library function which is getch(); whose definition is in conio.h
which stands for console input output function. It is used to show output of program in console.

Output:





Other Useful information:

printf("hello world how are you");
it will print the whole sentence in one line. if you want to write "how are you" in next line or want to give space equal to 1 tab then you have to use the following escape sequences:

\n (newline)
\t (tab)
\v (vertical tab)
\f (new page)
\b (backspace)
\r (carriage return)

let me try one of them in program:




#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr() 
printf("Hello World \n How Are You");
getch();
}

Note: I have used clrscr(); statement to clear the old output.

Output:




If you Liked our post then don't forget to share your views with us. It will help us to judge our work.

No comments:

Post a Comment