Getting Started with C Programming
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)
- In C programming smallest possible program that does nothing is :
ORint main() { // Here we write something return 0; }
So, In Cvoid main() { // Here we write something }
main()
is unique function which is already defined in C language. Execution of C program starts frommain()
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. - If you are using compiler other than Turbo C you may not require
clrscr()
andgetch()
and you do not require to includeconio.h
- So what are we doing inside
main()
function? First, we are executingclrscr();
which clears the output window (if there is anything in output window that will be erased). - Second, we are executing
printf("Hello, World!");
which displays the text "Hello, World!" to the output screen. Here, header filestdio.h
is included because functionprintf()
is defined instdio.h
header file. - 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