Chapter 1
Chapter 1
Modular Programming
Using Functions in C
DAISY JEAN A. CASTILLO
Instructor
01 Types of Functions
Elements of user-defined
Lessons
03 function
04 Using functions
05 Definition of function
06 Function Call
07 Return Statement
08 Function Declaration
Lessons
09 Category of functions
10 Scope of visibility
12 Recursion
Modularity
Modular Programming Using
Functions in C
action
Modular Programming Using
Functions in C
Functions are basically special type of programs, which
perform a specific task, but don’t work independently, as
main function does.
Main Function
Main Function
Concept of Function
Calling Program Data
Called
Calling Program
Program
Return
Value
C program with sumlist function which
adds given 3 numbers.
Standard Library C Functions
Function 4 Function 1
main() main()
function function
Function 3 Function 2
Advantages of Using Functions
1. Modularity
• With the use of functions, modularity gets automatically
incorporated in the program. Thus a single program gets
divided into small modules, obviously maintaining small
modules is much easier than maintaining a single large
program.
Advantages of Using Functions
2. Reusability
• If function is being used then to perform the same function
again within the program, the code need not be written again.
Only one line for calling the function can be written, which
would perform the task. This not only saves effort and time but
also reduces the length of the program.
Advantages of Using Functions
2. Reusability
• Since function written for one program, can be used in other
programs also hence programming becomes easy. Time and
efforts reduce to a considerable extent.
D on’t
R epeat
Y ourself
keep your code
D R Y
Elements of User-Defined Function
3. Argument/Parameter list
• Argument list is basically a list of variables along with their
data types. These are the variables in which function receives
the data from the calling program.
4. Body of the function
• Body of the function comprises of all those C statements,
which are to be executed, within the function.
Elements of User-Defined Function
Function name
Function data type Argument list
Body of
the function
Using Functions
LOCAL VS EXTERNAL
remain accessible within values are accessible
the function, in which within and outside the
they are declared function
2^3
= 2*2*2
Recursion Sample 2 - C program which accepts base and exponent
from the user and print its power value using the power function.
End of Chapter 1.
Thank you!