Chapter 1.4 - Describe the basic structure of C program
BASIC STRUCTURES OF C PROGRAMS
The examples discussed so far illustrate that a C program can be viewed as a group of building blocks called functions. A function subroutine that may include one or more statements designed to perform a specific task.
To write a C program, we first create functions and then put them together. A C program may contain one or more sections as shown in Fig. 9.
![]() |
Fig. 9 An overview of a C program |
Documentation Section -
The documentation section consists of a set of comment lines giving the name o program, the author and other details, which the programmer would like to use later.
Link Section -
The link section provides instructions to the compiler to link function from the system library.
Definition Section -
The definition section defines all symbolic constants.
Global Declaration Section -
There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all functions. This section also declares all the user-defined functions.
main() Function Section -
Every C programs must have one main() function section. This section contains two parts, declaration part, an executable part. The declaration part declares all the variable used in the executable part, There is at least one statement in executable part. These two parts must appear between the opening and the closing braces. The program executation brgins at the opening brace and ends at the closing brace. The closing brace of the main fumction section is the logical end of progtam. All statements in the declaration and executable parts end with a semicolon (;).
Subprogram Section -
Note - All Sections, expect the main function section may be absent when they are not required.
Comments
Post a Comment
Ask Me Everything About Programming.