Now let us examine the various components of the above program. All C programs are made up of one or more functions, each performing a particular task. The first line of the program
#include
tells the compiler to include information about the standard input/output library. This is called the preprocessor directive. In a C program, preprocessor directives should come first followed by global variable definitions, if any. After these functions follow.
The main () function
Every program has a special function named main. It is special because the execution of any program starts at the beginning of its main function. When a function is called, it is usually provided with a list of values called arguments or parameters.
The parentheses () are used for passing parameters to a function. The arguments that a function expects are specified in a parenthesized parameter list following the function name. The keyword void enclosed with the parenthesis indicates that no "parameters" or "arguments are expected by this routine.
An opening brace "{" following main function and its parameter list marks the beginning of the function body and similarly, the end of the function body is indicated by a closing brace at the end. In the function body, the variable declarations (if needed) and the statements are added. Statements specify the computing operations necessary to achieve the desired result and variables hold values during the computation.
In the above example, the main function contains two statements. The first statement
Printf ("This is a test program");
is a call to the standard library function printf. There are several commonly used computations that are required in many programs. Instead of making every programmer to write code for such computations, C provides a standard library of commonly used functions.
All compilers have a standard library, which is a collection of commonly used C functions use by other C programs, The prototypes for these functions are specified in a standard set of header files.
The printf routine is a function in the c system that prints or displays it argument at the terminal or on the video screen. The last two characters in the string namely the backslash () and the letter n together are known as the new line character ( ). A newline character tells the C system to do precisely what its name implies - to go to a new line. Any characters printed after the newline character will then appear on the next line of the terminal or display.
Thus, we can understand that a typical C program has the following sections
The scanf() statement is another library function. It reads data from the keyboard and assigns that data to one or more program variables.
The return statement is part of a function. It returns the result to the program that called any function.
Comments are explanatory remarks made within a program. They help to understand what the complete program is about, what a specific group of statements is meant to accomplish, or what one line is intended to do. Any line of text bounded by asterisks and enclosed within slashes is a comment. Comments don't affect program execution and they can be placed anywhere within a program. For example
/* This line indicates successful completion */
is a comment line. Now let us proceed to study how the C program is compiled and executed.