Course on C Programming/Why Documentation Area?

From WikiEducator
Jump to: navigation, search

Why Documentation Area?

Before writing a Program it is a good idea to write about the program. You may also want to write the algorithm of the proposed program, its constraints etc. You may write all these information in the Documentation area of the program with the help of comment lines. (The information enclosed in /* and */ are called comments.) The comment lines are not compiled. Documentation is very useful as it helps you and other programmers to understand the logic of the program at any point of time.

Why Preprocessor and Declaration Area?

In the preprocessor and declaration area you may define all symbolic constants and function prototypes. Symbolic constants help in program readability and maintenance. For example, in the example program above instead of using 9999 you are using MAXINT which indicates highest integer value allowed in the program. Thus, the use of MAXINT in comparison gives you better readability. Please also note that in case you want to change the MAXINT value to 1000, then you just need to do the change at the top of the program and recompile the program. You can also use this area to establish linkages to other files in a C program. These linkage statements provide instructions to the compiler to link to executable functions from the system libraries.

You can also define header files and function prototypes here. The The header files contains declaration of standard input output functions used in C and are included in Programs as per the need. There are several header files most common of these is stdio.h which contains declarations of standard input and output functions (hence the name stdio.h). Function Prototype declares the requirement of a function and its type in the beginning itself. You can see the prototype of such function that has been used in this program(the findbig function)

What are Global Variables?

All functions in C have variables (called local variables) that can be used by only those functions. The variables that may be used by all the functions of a program are called global variables. Global variables are declared in the Global declaration are that is outside of all the functions. In general, a good program should NOT have many global variables.

What is the main Function?

You must have ONLY one main() function in every C program. The execution of a C program starts from this function. The main function contains the declarations and executable statements. C Program requires you to declare all the variable that you want to use in the program statements. As you know each declaration and statement in C is terminated by a semicolon (;). A C Program in addition to main function may consist of many other functions. These functions can be used in the main function for performing some tasks.