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.

Significance of C Language

The increasing acceptance of C is basically due to its many desirable qualities. C is a strong language whose rich set of built-in functions and operators can be used to write any complex program effectively. C is a high-level language, it uses compiler as its translator, the C compiler combines the capabilities of an assembly (low-level programming) language with features of high-level language and therefore it is well suited for writing both system software and application software.

Programs written in C are efficient and fast. This is due to its variety of data types and powerful operators. For example, C is many times faster than BASIC. Its strength lies in its built-in functions. C is highly portable, means that programs written for one computer can be run on another with little or no modifications. Portability is important for software with different operating systems.

C is a structured programming language, thus requiring the user to think of a problem in terms of functions or blocks. A proper collection of these blocks would make a complete and efficient program. The modular structure helps the programmer to makes program debugging, testing and maintenance easier.

Another important feature of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. Anyone can continuously add their own functions to C library. With the large collection of functions, the programming in C is simple.