A Sample C Program| Brief Explanation of a C Program

Here is a sample C program. This program of will print Hello World!

#include<stdio.h>

int main() {

printf(“Hello World!”);

return 0;

}

Brief Explanation of each line of the program is given below

#include<stdio.h>

Here #include is preprocessor directive. Preprocessor directives are commands that are processed before the source code is compiled. They are begin with # symbol.

stdio.h is header file. It is one of the most commonly used header files in the C Standard Library. stdio.h stands for “Standard Input Output Header File“. It must be included at the beginning of a C program using #include preprocessor directive.

#include command tells the C preprocessor to include stdio.h file from the C library in the program before compilation. The stdio.h file contains functions such as scanf() and printf() to take input and display output respectively. Including stdio.h at the beginning of a C program using #include makes these input/output functions available for use within the code.

int main() { ….. }

Here main() is the function name and int is the return type of this function. It is a compulsory part of every C program. It is a special function used to inform the compiler that the program starts from there. Execution of every C program starts from main() function. Logically every program must have exactly one main() function. int indicates that the main function is expected to return an integer value.

The curly braces {} define the scope of the main function, containing the instructions to be executed. The opening curly bracket ‘{’ indicates the beginning of the main function and the closing curly bracket ‘}’ indicates the end of the main function.

printf(“Hello World!”) ;

This command tells the compiler to display the message “Welcome to C programming”. printf() is a function from the stdio.h library used to display the output onto the screen. The text to be printed is enclosed in double quotes.

The semicolon serves as the statement terminator. Semicolon character at the end of the statement is used to indicate that the statement is ending there. Each executable statement should have a ‘;’ to inform the compiler that the statement has ended. Thus, in ‘C’ the semicolon terminates each statement.

return 0;

This statement concludes the main function. The return statement is used to return a value from a function and indicates the finishing of a function. The value ‘0’ means successful execution of the function.

Leave a Comment