Basic Structure of C Program

A C program can be developed from a basic structure. The general structure of C program is as shown below( which is also called an overview of a c program) –

/* Basic strucutre of C program */      --1
#include<stdio.h> /*Header file*/       --2
#incldue<conio.h>
void main()                             --3
{                                       --4
    int var1,var2;			--5
    char nm[10];

    statement 1;		        --6
    statement 2;
}				        --7

1. Comment statements

Commenting statements are the non executable statements. Comment can be started by using ” /* ” and end with ” /*” .  This statement doesn’t contributes to the output but it is used in the programs for user help,  to make the coding in the program easily readable.  This statement can be used anywhere in the program. Also this is optional. It is not necessary to use them in the program if you don’t want to use.

2. Header File (#include)

Here a standard input/output header file is used. With this header file only all the input output statements can be used or executed. If this is the not used then printf(),  scanf(),  and other input output functions will not work.  C programming language is rich is header files. These are a lot of header files with which a lot of functions/statements can be used or executed. A C program may also use multiple header files in one program.

3. void main()  or main()

void main() program is the C program’s main structure in which we process some statements and make the logic of the program.

4. Beginning of the C Program

The beginning of the C program is done by using left or opening curly brace ” { “.

5. Data type declaration

Now the data types are declared like int, float, double and variable names are also declared to use in the program.

6.Executable Statements

Here statements are being executed. This section has reading, writing and processing statements having input/ output function, library function, formulas, conditional statements, looping statements and function calling statements. In this section, all of the C statements  except control statements end with ” ; ” (semicolon).

7. End of the C Program

Program ends with the right of closing curly brace ” } “.

These are some more sections which are used in the C program but with these 7 section you can start making good programs. We will discuss more sections in the later chapters till then we can start making C programs.

yashan has written 70 articles

One thought on “Basic Structure of C Program

Cancel reply

Leave a Reply to ceswari

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>