Structure of a ‘C’ program:
Documentation
Section
|
||||
Include
Section ( Preprocessor Directives)
|
||||
Define
Section
|
||||
Global
variable Declaration
|
||||
main(
) [function]
{
}
|
||||
|
Preprocessor
directives contains statements these are included before the execution of main
function. All the preprocessor directives starts with ‘#’ symbol.
Global variables are those variables
certain used in any part of the program.
Main function is the function
where the actual program execution starts. The word "main" is very
important, and must appear once, and only once, in every C program. This is the
point where execution is begun when the program is run.
A local variable is the one that is
used only with inn the truncated block.
Executable
part contains different types of statements related to Input and Output,
arithmetic, logical, data transfer statements.
A
user defined function is one that is defined by the user explicitly.
o
Every C program consists of one or more
functions. A function is nothing but a group or sequence of C statements that
are executed together.
o
Each C program function performs a
specific task. The ‘main()’ function is the most important function and must
be present in every C program. The execution of a C program begins in the main()
function.
o
Preprocessor directives contains
statements these are included before the execution of main function. All the
preprocessor directives starts with ‘#’
symbol.
o
Global variables are those variables
certain used in any part of the program.
o
Main
function is the function where the actual program execution starts. The word
"main" is very important, and must appear once, and only once, in
every C program. This is the point where execution is begun when the program is
run.
o
A local variable is the one that is used
only with inn the truncated block.
o
Executable part contains different types
of statements related to Input and Output, arithmetic, logical, data transfer
statements.
o
A user defined function is one that is
defined by the user explicitly.
o
Example:
/* A program to print welcome message */
#include<stdio.h>
main()
{
printf(“Hello, world”);
}
main()
{
printf(“Hello, world”);
}
In the
program, the information enclosed between ‘/* */’ is called a ‘comment’ and may
appear anywhere in a C program. Comments are optional and are used to increase
the readability of the program.
The
‘#include’ in the first line of the program is called a preprocessor
directive. A preprocessor is a program that processes the C program
before the compiler. All the lines in the C program beginning with a hash (#)
sign are processed by the preprocessor.
‘stdio.h’ refers to a file supplied
along with the C compiler. It contains ordinary C statements. These statements
give information about many other functions that perform input-output
roles.
Thus, the statement
‘#include<stdio.h>’ effectively inserts the file ‘stdio.h’ into the file
hello.c making functions contained in the ‘stdio.h’ file available to the
programmer. For example, one of the statements in the file ‘stdio.h’ provides
the information that a function printf() exists, and can accept a string
(a set of characters enclosed within the double quotes).
The next statement is the main()
function. As we already know, this is the place where the execution of the C
program begins. Without this function, our C program cannot execute.
Next comes the opening brace ‘{’,
which indicates the beginning of the function. The closing brace ‘}’ indicates
the end of the function.
The
statement printf() enclosed within the braces‘{ }’ informs the compiler
to print (on the screen) the message enclosed between the pair of double
quotes. In this case, ‘Hello, world’ is printed.