Structure C Program Notes
Structure C Program Notes
Structure of C program
Structure of C program
Documentation section
Link section
Definition section
Global declarations;
main ( )
{
declaration part;
executable statements;
}
user defined functions
1
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept
sample program 1
#include<stdio.h>
main ( )
{
printf ( “ First C program “); /* displaying message */
}
sample program 2
# include<stdio.h>
main ( )
{
int a =10, b = 20; /* declaration and initialization of input data */
int sum, sub;
add = a + b ;
diff = a – b ; /*computation of arithmetic operation */
printf ( “ sum = % d “, sum ) ; /* Display the results */
printf ( “difference = % d “, sub ) ;
}
Documentation Section : It consists of a set of comment lines giving the name of the
program, the author and other details, which the programmer would like to see later.
Comments can be added to any of instructions in the program
Link Section: This provides instructions to the compiler to link functions from the
system library. It consists of preprocessor statements(directives) which begin with #
symbol. These direct the C preprocessor to include header files(linking functions)
Examples :
#include <stdio.h>
#include”test.h”
#include<math.h>
2
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept
Global declarations : Variables or functions that are used in the main( ) function and
also in other user defined function are called global variables (or functions)The
declaration is made before main( )
main() :Every C program must have one main ( ). Execution of C program starts from
main(). No C program is exeuted without main(). It should be written in lowercase letters
and should not be terminated by a semicolon. It calls other library functions and user
defined functions.There must be one and only one main( ) function in every C program .
Declaration part : All the variables, arrays, user defined functions etc used in the C
program are declared and may be initialized with their basic data types.
User defined Functions : These are subprograms generally called as functions. These
contain set of statements to perform a specific task. These are written by the user, hence
the name user defined functions.
Programming Style
Documentation
It is an explanatory note on the purpose/use of instruction/program for which it has
been written. Explanatory note is called a comment. It explains how the program
3
Programming Fundamentals with C Padmashree Desai, Asst.Prof, CSE Dept
works and how to interact with it. Thus it helps the other programmer to understand
the program
There are two types of documentation
• Internal documentation
• External documentation
Internal documentation
• It is a comment statement within a program
• It helps the programmer to understand / update the code at later stage.
It is done by
• Defining meaningful variable names
• Including remarks or comments in a program code
• Adding comments on every module indicating its purpose
• Presenting the program code clearly by inserting spaces, blank lines and using
indentation
External documentation
• It is an executable statement in a program. It may be a message to the user to
respond to the program requirement. This is accomplished using output
statements. It makes the program more attractive and interactive.
Some sample examples are :
• printf(“Input numbers one by one”);
• printf(“Do you want to continue?”);
-------------------end-------------------------
Uploaded by Nix