First Hello world program using C programming

0

In our previous post we discussed about the basic features about the C programming. Today we will talk about a basic hello world programming. Let’s talk about the program shown below.

#include <stdio.h>

#include <conio.h>

void main()

{

clrscr();

printf(“Hello world\n”);

getch();

sleep(5);

}

First of all we need to know why we include the header files. Here .h file is a header file. We include this file to call the sub programs that usually contained in the header files. Here stdio means standard input output. This standard input output is used to get input or output of the program. Here we will use this header just to print the “hello world” sentence.

This header file mostly used for taking input and showing output. Next conio.h file. This file means console input output. This file usually used for using the console as an interface for the program result. But there we are using this header file just to show the output on console.

Void main is the main function of our C programming language. The compiler will look for this function in the script to begin the process.  As we know main function is a must function we have to declare on C programming. This will be

Void main() {

The coding will go here.

}

We almost explained the basic structure of our program. Her we have left only few things which are actually pseudo code. Here we have three functions and one pseudo code. The functions are clrscr, getch and sleep. The pseudo code is printf. Lets just explain why I used these here.

Clrscr: this function is used for clearing the previous output from the consol. This function belongs to the conio.h header file. We can avoid this function if we don’t want to clear the previous result.

Getch: this function also belongs to conio.h header file. Getch means get characters. Again the program will work if we do not use this function. But we are using this to get the output on run.

Sleep: this function is optional from top to bottom. Although this function have a huge implementation when we are going to write a complex and big program. This just breaks the process after the time mentioned in the argument.

Next the pseudo code “printf”. Simply this code is used to print the output of the program. If we have nothing to show as a output then we can avoid this too.

The above program is actually the program where a user can get a output. If we want to simply more, then we can write the program as below:

#include <stdio.h>

void main()

{

printf(“Hello world\n”);

}

This will also run faster and the performance will be much better. But a simple user will not understand if the program is working or not. So its better to learn the basics using more resource.

Once we have a clear concept about our program then we can omit few unnecessary functions and pseudo codes from our script.

Happy programming.

Leave A Reply

Your email address will not be published.