Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Functions in c language1
1. FUNCTIONS IN C LANGUAGE
By
CH SRILAKSHMI PRASANNA MTech(PhD)
2. INTRODUCTION TO FUNCTIONS
A large program in C can be divided to many subprogram.
A function is a self contained sub program which does a specific task.
A C program consists of one or more functions.
A functions can also be termed as method, sub routine, procedure.
A C program must contain at least one function it must be main() function.
Classification of Function User defined function
Library function
3. INTRODUCTION TO FUNCTIONS
Library Functions:
• already defined in the system libraries.
• Programmer can reuse the existing
code in the system libraries
which is helpful to write error free code.
• User must be aware
of syntax of the function.
6. INTRODUCTION TO FUNCTIONS
User defined Functions:
In C programming language, users can also create their own
functions. The functions that are created by users are called as user
defined functions.
The user defined functions are of 4 types:
Function without Parameters(arguments) and without Return value
Function with Parameters(arguments) and without Return value
Function without Parameters(arguments) and with Return value
Function with Parameters(arguments) and with Return value
8. INTRODUCTION TO FUNCTIONS
A function declaration tells the compiler about a function name and how to call the
function.
Calling
function
Called
function
9. INTRODUCTION TO FUNCTIONS
The Function which calls another Function is called Calling Function and
Function which is called by another Function is call Called Function.
10. INTRODUCTION TO FUNCTIONS
Advantage of functions in C:
• By using functions, we can avoid rewriting same logic/code again and again in a
program.
• We can call C functions any number of times in a program and from any place in a
program.
• We can track a large C program easily when it is divided into multiple functions.
• Reusability is the main achievement of C functions.
11. FUNCTION WITHOUT PARAMETERS AND WITHOUT
RETURN VALUE
In this type of functions there is no
data transfer between calling function
and called function. Simply the
execution control jumps from calling-
function to called function and
executes called function, and finally
comes back to the calling function.
12. FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In this type of functions there is data
transfer from calling-function to called
function (parameters) but there is no data
transfer from called function to calling-
function (return value). The execution
control jumps from calling-function to
called function along with the parameters
and executes called function, and finally
comes back to the calling function.
Actual: num1,num2
Formal: a, b
13. FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
The parameters(arguments) specified in calling function are said
to be Actual Parameters (arguments).
The parameters(arguments) declared in called function are said
to be Formal Parameters(arguments).
The value of actual parameters(arguments) is always copied into
formal parameters(arguments).
14. FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In C Programming Language, there are two methods to pass
parameters from calling function to called function and they are
as follows...
Call by Value
Call by Reference
15. FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In call by value parameter passing method, th
copy of actual parameter values are copied t
formal parameters and these formal parameter
are used in called function. The changes made on
the formal parameters does not effect the value
of actual parameters. That means, after th
execution control comes back to the callin
function, the actual parameter values remain
same.
the variables num1 and num2 are called
actual parameters and the variables a and b
are called formal parameters. The value of
num1 is copied into a and the value of
num2 is copied into b. The changes made
16. FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
Call by Reference
In call by reference parameter passing
method, the address of the actual
parameters is passed to the called
function and is received by the formal
parameters (pointers). Whenever we use
these formal parameters in called
function, they directly access the
memory locations of actual parameters.
So the changes made on the formal
parameters effects the values of actual
parameters.
The addresses of variables num1 and
num2 are copied to pointer variables
a and b. The changes made on the
pointer variables a and b in called
function effects the values of actual
parameters num1 and num2 in calling
17. FUNCTION WITHOUT PARAMETERS AND WITH RETURN
VALUE
In this type of functions there is no data transfer
from calling-function to called-function
(parameters) but there is data transfer from
called function to calling-function (return value).
The execution control jumps from calling-
function to called function and executes called
function, and finally comes back to the calling
function along with a return value.
18. FUNCTION WITH PARAMETERS AND WITH RETURN
VALUE
In this type of functions there is data
transfer from calling-function to called-
function (parameters) and also from
called function to calling-function
(return value). The execution control
jumps from calling-function to called
function along with parameters and
executes called function, and finally
comes back to the calling function
along with a return value.
19. RECURSIVE FUNCTIONS IN C
In C programming language, function calls can be made from the
main() function, other functions or from the same function itself.
A function called by itself is called recursive function.
When a function is called by itself, the first call remains under execution
till the last call gets invoked. Every time when a function call is invoked,
the function returns the execution control to the previous function call.
20. RECURSIVE FUNCTIONS IN C
When a function is called by
itself, the first call remains under
execution till the last call gets
invoked. Every time when a
function call is invoked, the
function returns the execution
control to the previous function
call.