adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Basic structure of a C program

Basic structure of a C program:

   C program consists of a group of blocks called functions. A function is a  sub-routine that may include one or more statements depending on specific tasks. A C program has one or more sections as shown below:-

 

      


   (A) Documentations Section:- It consists of comment lines which may be used by programmer in future to know about the program. It is not a compulsory part of a program.
  
      Notes:- Comment :- A line beginning with a double slash(\\) is called single comment line. And a line beginning with  /* and ending with */ is called multiple comment lines.

  (B) Link Section :- It provides the information to the compiler to link the header file or any other file from system library which contain library function.
                      Example :- #include<stdio.h>
                                         #include<stdlib.h>
   (C) Definition Section :- under this section we define symbolic constant(macro).
                     Example :- #define PI  3.14
   (D) Global Declaration Part:- Variable that are used in more than one function are called global variables. Such variables are declared in global declaration section.
             Notes :- Definition of global and local variable
   (E) Main Function Section :- Every C program must have one and only one main function. This section is divided into two parts- Declaration part and Executable part. In the declaration part we declare all the variables used in the executable part. At least one statement should be present in the executable part. These two parts must appear between the opening and closing braces({}). The program execution begins at the opening brace and ends at the closing brace. All statement in the declaration part and executable part end with a semi-colon(;) known as the termination symbol.
   (F) Sub Program Section :- The sub program section contains the user-defined functions that are called in the main functions.

     Structure-  void main()
                          {
                             function1()
                           }
                       void function1()
                          {          
                           user defined function()
                          }
                                         
                                                 
  Previous :- Structure of a C program                     Next :- Variable & Constants



Post a Comment

1 Comments