Basic Program in C language

   We are going to learn a simple “Hello World” C program in this section. Also, all the below topics are explained in this section which are the basics of a C program.

    1. C basic program with output and explanation
    2. Steps to write C programs and get the output
    3. Creation, Compilation and Execution of a C program
      • How to install C compiler and IDE
    4. Basic structure of a C program
1. Basic Program in c Language:


Hello World!

Explanation for above C basic Program:

Let’s see all the sections of the above simple C program line by line.
1#include <stdio.h>This is a preprocessor command that includes standard input output header file(stdio.h) from the C library before compiling a C program
2int main()This is the main function from where execution of any C program begins.
3{This indicates the beginning of the main function.
4/*_some_comments_*/whatever is given inside the command “/*   */” in any C program, won’t be considered for compilation and execution.
5printf(“Hello_World! “);printf command prints the output onto the screen.
6getch();This command waits for any character input from keyboard.
7return 0;
This command terminates C program (main function) and returns 0.
This indicates the end of the main function.

2. Steps to write programs in C language and get the output:

      Below are the steps to be followed for any C program to create and get the output. This is common to all C program and there is no exception whether its a very small C program or very large C program.
C Basic program

3. Creation, Compilation and Execution of a C program:

    • If  you want to create, compile and execute C programs by your own, you have to install C compiler in your machine. Then, you can start to execute your own C programs in your machine.
    • You can refer below link for how to install C compiler and compile and execute C programs in your machine.
    • Once C compiler is installed in your machine, you can create, compile and execute C programs as shown in below link.

C – Environment Setup Using IDE tool

C – Environment Setup Using GCC compiler

4. Basic structure of C program:

     Structure of C program is defined by set of rules called protocol, to be followed by programmer while writing C program. All C programs are having sections/parts which are mentioned  below.
    1. Documentation section
    2. Link Section
    3. Definition Section
    4. Global declaration section
    5. Function prototype declaration section
    6. Main function
    7. User defined function definition section

Example C program to compare all the sections:

You can compare all the sections of a C program with the below C program.


This is a C basic program
Sum of two numbers : 2

Description for each section of a C language program:

    • Let us see about each section of a C basic program in detail below.
    • Please note that a C program mayn’t have all below mentioned sections except main function and link sections.
    • Also, a C program structure mayn’t be in below mentioned order.
1Documentation sectionWe can give comments about the program, creation or modified date, author name etc in this section. The characters or words or anything which are given between “/*” and “*/”, won’t be considered by C compiler for compilation process.These will be ignored by C compiler during compilation.
Example : /* comment line1 comment line2 comment 3 */
2Link SectionHeader files that are required to execute a C program are included in this section
3Definition SectionIn this section, variables are defined and values are set to these variables.
4Global declaration sectionGlobal variables are defined in this section. When a variable is to be used throughout the program, can be defined in this section.
5Function prototype declaration sectionFunction prototype gives many information about a function like return type, parameter names used inside the function.
6Main functionEvery C program is started from main function and this function contains two major sections called declaration section and executable section.
7User defined function sectionUser can define their own functions in this section which perform particular task as per the user requirement. appreciates your contribution please mail us the questions you have to so that it will be useful to our job search community

No comments:

Top Blogs