Copyright © 2010 K-Tutorials.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

The contents are updated or revised periodically; the document version will be changed based on the update or revision of the contents.

Document version: 1.0

Sunday, January 22, 2012

General Structure of a C Program


1. Documentation Section:-
  • Here we can write a set of comment lines
  • This includes Title of the Program, Author Name, Company Name, Date of Creation and Other details if any
  • Data and summary of the program.

2. Link Section:-
  • It is also called Header File Declaration or Include Section
  • It Links compiler to functions from System Library (Links Library functions of C)

3. Definition Section:-
  • Defines Symbolic Constants
E.g. #define PI 3.14

4. Global Declaration Section:-
  • Declaring Global Variables – Variables that are accessed by one or more functions are called “Global Variable”
  • Prototype declaration of C Functions
  • May contain Function Definition

5. Main Function Section:-
  • This is the Main Function of all C Programs - (main())
  • The program begins from here.
  • Main program starts from here

6. Sub Program Section:-
  • It has all User-Defined Functions that are called in main ( ) function or other sub functions defined by the user.
  • User-defined functions are generally placed immediately after main ( ) function.