Pages

Wednesday, 9 May 2018

First C Program – Print Hello World Message


First C Program – Print Hello World Message


We have gained lots of theoretical knowledge. Now its time to move on and write our first C program to print hello world message and understand it. It is the very first program that most of the people write when start learning any language.
Hello World C Program
This is a program to print “Hello World” message on screen.


#include<stdio.h>

void main()
{
 printf("Hello World");
}

#include<stdio.h>

void main()
{
 printf("Hello World");
}
Output
Hello World

Explanation

Now try to understand this program step by step.

1. #include<stdio.h>: First statement started with #, it is called pre-processor directive. We will learn about them thoroughly in later tutorials. #include<stdio.h> is used to include the stdio.h header file in our program. Header files contains the functions that we use in our program. Here we have used printf() function which is present in stdio.h header file.

2. void main(): Here main() is the function. A program always starts with the main() function and every program must have main(). Here void is the return type of this function. It means main() function will not return anything. The opening curly braces ({) and closing curly braces (}) shows the body of the function.

main() can also be called as a collection of statements.

3. printf(): Here printf() is another function. This is used to print the values on the screen. Its general form is

printf(“Statement you want to print on screen”);

4. Semicolon (;) is used for denoting the termination of statement. It is also called statement terminator in C Language.

How to compile and execute?
Here we are using  Codeblocks IDE that comes with GCC compiler. If you have not downloaded it yet then follow below link to know how to download and install it.