Basic Structure of ‘C’ Programs


BASIC  STRUCTURE  OF  C PROGRAM
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

Documentation Section   (Comments about the program)
Link Section                       (Header)
Global Declaration Section

main() Function Section

{
Declaration Part (Variable Declaration)
Executable Part (Statements)
}

Subprogram section
Function1
Function2
……….. (User-defined functions)
Function

The documentation section consists of a set of comment lines giving the name of the program, the author and other details which the programmer would like to use later.

The link section provides instructions to the compiler to link functions from the system library.

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,

1.       declaration part and
2.       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 the opening and the closing braces.

                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 the 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 may be absent when they are not required.

EXECUTING   OF   A ‘C’ PROGRAM

Executing a program written in C involves a series of steps. These are:

1. Creating the program
2. Compiling the program
3. Linking the program with functions that are needed from the C library
4. Executing the program.

The C Character Set:
A character denotes any alphabet, digit or special symbol used to represent information.
The characters in C are grouped into the following categories:
1. Letters
2. Digits
3. Special Characters
4. White Spaces

White spaces may be used to separate words, but are prohibited between the characters of keywords and identifiers.

1. Letters:
                     Uppercase A……Z
                     Lowercase a……z

2. Digits:
                 All decimal digits 0 ......... 9

3. Special Characters

ampersand(&)
Comma(,)
lessthansign(<)
Questionmark(?)
tilde(~)
apostrophe(‘)
dollarsign($)
minus(-)
Quotationmark(“)
underscore(_)
asterisk(*)
Exclamationmark(!)
numbersign(#)
rightbrace(})

backslash(\)
greaterthansign(>)
openinganglebracket(<)
rightbracket(])

caret(^)
leftbrace({)
percentsign(%)
rightparentheses())

closinganglebracket(>)
leftbracket([)
Period(.)
Semicolon(;)

Colon(:)
leftparenthesis(()
plussign(+)
slash(/)




4. White Space:  Blank space

Comments