FUNCTIONS-unit3
FUNCTIONS-unit3
FUNCTIONS
ECE Branch
What is a function in C
A function is a block of statements or group of statements that can be used to
perform a task.
• A function is known with various names like a method or a subroutine or a
procedure, etc.
• Functions are used to break up large programs into named sections or methods.
• Functions are used to write some piece of code once that has to run multiple
times.
• To create a function we need to know Function declaration, Definition and calling.
• A function declaration tells the compiler about a function's name, return type, and
parameters.
• A function definition provides the actual body of the function.
• Call a Function: Declared functions are not executed immediately. They are "saved
for later use", and will be executed when they are called. To call a function, write
the function's name followed by two parentheses () and a semicolon ;
Diagram of function
• It is much easier to write a structured program where a large
program can be divided into a smaller, simpler task.
• Allowing the code to be called many times
• Easier to read and update
• It is easier to debug a structured program where there error is easy
to find and fix. (OR)
1 Easy to implement and update.
2 Easy to read and understand.
3 Easy to debug.
4 Modularity can be achieved – Divides the large program in to
smaller ones.
5 Code re-usability
6 Reduces the code duplication(redundancy).
7 Length of the program can be reduced.
DEFINING A FUNCTION
• In C language A function definition consists of
function header and function body.
• The general form of a function Definition is as
follows: