Structure of C program
Comments Comments Section
// Author
/* About the program what it is doing */ Procedure oriented –
made up of functions,
Preprocessor Preprocessor directives
with at least main().
Directives # include<stdio.h> include header files from the standard libraries
# include”sample.h” include header files from the current folder, user defined headers
#define macro 2 //Macros are constants
Calculator
Global Variables
Variable and function Program
Int globalvar;
Declarations Function Prototypes or declarations
void functionglobal(int y); accessible to other .c files
void functionglobal1(int);
static void functionstatic(int); Visible only in this .c file Mul Add Div Sub
int main(void) //no command line arguments
Main function {
definition Statements User defined functions
}
Library functions
Other function void functionglobal(int y) // Function definition • printf
{ • Scanf
definitions • strcpy
Statements
}
Structure of C program Calculator
Program
Design1 Design2 Design3
Main.c Main.c Main.c Mul.h Mul.c Mul()
Operations Operations
User
User
Main()
Input
Main() Input
Main() Add.h Add.c Add()
Functions Mul User User
Output Input()
Add User Sub.h Sub.c Sub()
Mul() × Output()
Div
Add() +
Div.h Div.c Div()
Sub Div() %
User
Output
Sub()
-
Functions
Structure of C program
Entry and Exit of c program
#include<stdio.h>
Int var;
Int main(void)
Entry
{
UserInput();
UserOutput();
Exit return 1;
}
void UserInput() void UserOutput()
{ {
if(Add operation requested) printf(“Display the result”);
{ }
Add();
More details in C Execution model
}
}