Now we’ll start the practical work on C programming. We’ll start the programming using Hello World Program. We are going to start a first program of C language. Before going further in this tutorial, we recommend you to please go through the previous tutorial if you’re a beginner.
Open the Emulator and type the source code below.
clrscr(); //to clear the output screen
printf("Hello World!"); //text to display
getch(); //to hold the output screen
See the output of first program “Hello World!”
Now, compile and run the source code, you’ll see the “Hello World!” as an output of first program as shown below.
Source code explanation
The above two lines preceded by ‘#’ are header file where all the functions are defined.
#include<stdio.h>:In this file, ‘stdio’ stands for ‘Standard Input Output’. This header file contains all the functions that need to take input from the user and to display the output to the user. It contains the printf(), scanf() functions defined to process accordingly.
#include<conio.h>: In this file, ‘conio.h’ stands for ‘Console Input Output’. This file deals with the input output to and from the console.
Following is the explanation for the various functions defined in the code for fully understanding.
main(): As it’s name suggests, it is an important function in the C language. The program execution starts from the main function. As the C is an procedural language, it follows top-down approach for the execution of program.
clrscr(): This functions clears the output screen. It cleans the previously printed outputs.
printf(): The printf() function prints a value in the output screen. It is declared in the ‘conio.h’ header file.
getch(): This function holds the output screen. i.e. the output screen will not dismiss until we press any key.
void: This keyword is written before the function to show that the given function is not returning any value.
Always remember! The C program always start with the void main() function.
The clrscr() function is used to clear the output screen.
getch() function is used to hold the output screen.
We will see more advanced programs in further tutorials.