Saturday 17 November 2012

Programming with C Language - Basic structure of C Programs

Programming with C1.2 Basic structure of C Programs
 
Basic structure of C Programs   A C program can be viewed as a group of building blocks called functions. A function is a 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 shown in Fig. 1.1.
  Fig. 1.1 The documentation section consists of a set of comment(remarks) lines giving the name of the program, the author and other details which the programmer would like to use later. Comments may appear anywhere within a program, as long as they are placed within the delimiters /* and */ (e.g., /*this is a comment*/). Such comments are helpful in identifying the program's principal features or in explaining the underlying logic of various program features. The link section provides instructions to the compiler to link functions from the system library. The definition section defines all symbolic constants. 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 the functions. Every C program must have one main function section. This section contains two parts, declaration part and executable part. The declaration part declares all the variables used in the executable part. There is at least one statement in the executable part. These two parts must appear between opening and closing braces({ and }). The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program. All statements in the declaration and executable parts end with a semicolon(;). The subprogram section contains all the user-defined functions that are called in the main function. User-defined functions are generally placed immediately after the main function, although they may appear in any order. All sections, except the main function section may be absent when they are not required. Self Assessment Questions i) The documentation section contains a set of __________ lines. Ii) State true or false Every C program must have one main() function. iii) What are global variables?

No comments:

Post a Comment