SlideShare a Scribd company logo
1 of 23
Download to read offline
@2020 Presented By Y. N. D. Aravind
1
Presented By
Y. N. D. ARAVIND
M.Tech, Dept of CSE
Newton’s Group Of Institutions, Macherla
1
Session Objectives
Parameter Passing
Passing Arrays to Functions
Recursive Functions
Function Components
@2020 Presented By Y. N. D. Aravind
2
2
A function is a block of code that performs a specific task. It has a name and it is reusable
.It can be executed from as many different parts in a program as required, it can also return
a value to calling program.
All executable code resides within a function. It takes input, does something with it, then
give the answer.
A computer program cannot handle all the tasks by itself. It requests other program like
entities called functions in C. We pass information to the function called arguments which
specified when the function is called. A function either can return a value or returns nothing.
Function is a subprogram that helps reduce coding.
return_type function_name (argument list)
{
Set of statements – Block of code
}
@2020 Presented By Y. N. D. Aravind
3
3
Function in C
Basically there are two reasons because of which we use functions
1. Writing functions avoids rewriting the same code over and over.
For example - if you have a section of code in a program which
calculates the area of triangle. Again you want to calculate the
area of different triangle then you would not want to write the
same code again and again for triangle then you would prefer to
jump a "section of code" which calculate the area of the triangle
and then jump back to the place where you left off. That section of
code is called ..........„ function'.
2. Using function it becomes easier to write a program and keep
track of what they are doing. If the operation of a program can be
divided into separate activities, and each activity placed in a
different function, then each could be written and checked more
or less independently. Separating the code into modular functions
also makes the program easier to design and understand.
@2020 Presented By Y. N. D. Aravind
4
4
Why use Function
 Once a function is defined and called, it takes some data from the calling
function and returns a value to the called function.
 When ever a function is called, control passes to the called function and
working of the calling function is stopped.
 When the execution of the called function is completed, a control returns
back to the calling function and executes the next statement.
 The values of actual arguments passed by the calling function are received
by the formal arguments of the called function.
 The number of actual and formal arguments should be the same. If the
formal arguments are more than the actual arguments then the extra arguments
appear as garbage.
 The function operates on formal arguments and sends back the result to the
calling function.
@2020 Presented By Y. N. D. Aravind
5
5
How Function’s Work
Def:- The function which is referring another function is called “calling
function”.
Def:- The function which is referenced by another function is called “called
function”
@2020 Presented By Y. N. D. Aravind 6
Calling Function and Called Function
Actual Arguments and Formal Arguments
Def:- The arguments of calling functions are called “actual arguments”.
Def:- The arguments of called function are “formal arguments”.
Local Variables and Global Variables
Local variables:-
The local variables are defined within the body of the function or the block.
Other function cannot access these variables.
Global variables:-
Global variables are defined outside the main() function. Multiple functions
can use them.
@2020 Presented By Y. N. D. Aravind 7
C provides library functions for performing some operations. These
functions are present in the c library and they are predefined.
For example sqrt() is a mathematical library function which is used for
finding the square root of any number .The function scanf and printf()
are input and output library function similarly we have strcmp() and
strlen() for string manipulations. To use a library function we have to
include some header file using the preprocessor directive #include.
For example to use input and output function like printf() and scanf() we
have to include stdio.h, for math library function we have to include
math.h for string library string.h should be included.
@2020 Presented By Y. N. D. Aravind
8
8
Library Function’s in C
A user can create their own functions for performing any specific
task of program are called user defined functions. To create and
use these function we have to know these 3 elements.
1. Function Declaration
2. Function Definition
3. Function Call
@2020 Presented By Y. N. D. Aravind 9
User defined Function’s in C
1. Function Declaration
The program or a function that calls a function is referred to as the calling program or calling
function. The calling program should declare any function that is to be used later in the program
this is known as the function declaration or function prototype.
2. Function Definition
The function definition consists of the whole description and code of a function. It tells that what
the function is doing and what are the input outputs for that. A function is called by simply writing
the name of the function followed by the argument list inside the parenthesis. Function definitions
have two parts:
Function Header
The first line of code is called Function Header. int sum( int x, int y)
It has three parts
(i). The name of the function i.e. sum
(ii). The parameters of the function enclosed in parenthesis
(iii). Return value type i.e. int
Function Body
Whatever is written with in { } is the body of the function.
3. Function Call
In order to use the function we need to invoke it at a required place in the program. This is known
as the function call.
@2020 Presented By Y. N. D. Aravind 10
User defined Function’s in C
A function depending on whether arguments are present or not and
whether a value is returned or not may belong to any one of the
following categories:
I. Functions with no arguments and no return values.
II. Functions with arguments and no return values.
III. Functions with arguments and return values.
IV. Functions with no arguments and return values.
@2020 Presented By Y. N. D. Aravind 11
Categories Of Function’s
There is no data communication between the calling portion of a
program and a called function block. The function is invoked bya calling
environment by not passing any formal arguments and the function also
does not return back any value to the caller.
No Input
No Output
No data communication between functions
@2020 Presented By Y. N. D. Aravind 12
Function’s with no arguments and no return values
function1()
{
---------------------
---------------------
---------------------
function2(); /* function call*/
---------------------
---------------------
}
function2()
{
---------------------
---------------------
---------------------
---------------------
---------------------
}
#include<stdio.h>
#include <conio.h>
void maximum();
{
int x,y,z,max;
printf( “ Enter three Numbers n”);
scanf(“%d%d%d”, &x,&y,&z);
max = x;
if(y > max)
max = y;
if(z > max)
max = z;
printf(“Maximum = %d n”,max);
}
void main()
{
clrscr();
maximum();
getch();
}
@2020 Presented By Y. N. D. Aravind 13
Function’s with no arguments and no return values
Input- Output
Enter three Numbers
1 2 3
Maximum = 3
The second type of user defined function passes some formal arguments
to a function but the function does not return back any value to the caller.
It is an one – way data communication between the calling portion of a
program and a called function block.
Values
of arguments
No return values
One – way data communication between functions
@2020 Presented By Y. N. D. Aravind 14
Function’s with arguments and no return values
function1()
{
---------------------
---------------------
---------------------
function2(x); /* function call*/
---------------------
---------------------
}
function2(a)
{
---------------------
---------------------
---------------------
---------------------
---------------------
}
#include<stdio.h>
#include <conio.h>
void maximum(int, int, int);
void main()
{ int x,y,z;
clrscr();
printf( “ Enter three Numbers n”);
scanf(“%d%d%d”, &x,&y,&z);
maximum(x,y,z);
getch();
}
void maximum(int a, int b, int c)
{ int max;
max = a;
if(b > max)
max = b;
if(c > max)
max = c;
printf(“Maximum = %d n”,max);
}
@2020 Presented By Y. N. D. Aravind 15
Function’s with arguments and no return values
Input- Output
Enter three Numbers
1 2 3
Maximum = 3
The third type of user defined function passes some formal arguments to
a function from a calling portion of the progra and the computed value, if
anyy, is transferred back to the caller. Data are communicated between
the calling portion of a program and a called function block.
Values
of arguments
Function results
Two – way data communication between functions
@2020 Presented By Y. N. D. Aravind 16
Function’s with arguments and with return values
function1()
{
---------------------
---------------------
---------------------
function2(x); /* function call*/
---------------------
---------------------
}
function2(a)
{
---------------------
---------------------
---------------------
---------------------
---------------------
return(z);
}
#include<stdio.h>
#include <conio.h>
int maximum(int x, int y, int z);
void main()
{ int x,y,z,maxi;
clrscr();
printf( “ Enter three Numbers n”);
scanf(“%d%d%d”, &x,&y,&z);
maxi = maximum(x,y,z);
printf(“Maximum = %d n”,maxi);
getch();
}
int maximum(int x, int y, int z)
{ int max;
max = x;
if(y > max)
max = y;
if(z > max)
max = z;
return(max);
}
@2020 Presented By Y. N. D. Aravind 17
Function’s with arguments and with return values
Input- Output
Enter three Numbers
1 2 3
Maximum = 3
The fourth type of user defined function, the function is invoked by a
calling environment by not passing any formal arguments to a function
but the computed value, if any, is transferred back to the caller. Data are
communicated between the calling portion of a program and a called
function block in one way.
No Input
Function results
One – way data communication between functions
@2020 Presented By Y. N. D. Aravind 18
Function’s with no arguments and return values
function1()
{
---------------------
---------------------
---------------------
function2(); /* function call*/
---------------------
---------------------
}
function2()
{
---------------------
---------------------
---------------------
---------------------
---------------------
return(z);
}
#include<stdio.h>
#include <conio.h>
int maximum();
void main()
{ int max;
clrscr();
max = maximum();
printf(“Maximum = %d n”,max);
getch();
}
int maximum()
{ int x,y,z,max;
printf( “ Enter three Numbers n”);
scanf(“%d%d%d”, &x,&y,&z);
max = x;
if(y > max)
max = y;
if(z > max)
max = z;
return(max);
}
@2020 Presented By Y. N. D. Aravind 19
Function’s with no arguments and return values
Input- Output
Enter three Numbers
1 2 3
Maximum = 3
Most programming languages have 2 strategies to pass parameters. They are
i. pass by value
ii. pass by reference
Pass by value (or) call by value :-
In this method calling function sends a copy of actual values to called function, but the
changes in called function does not reflect the original values of calling function.
Pass by reference (or) call by address :-
In this method calling function sends address of actual values as a parameter to called
function, called function performs its task and sends the result back to calling function.
Thus, the changes in called function reflect the original values of calling function. To
return multiple values from called to calling function we use pointer variables.
Calling function needs to pass ..„&‟ operator along with actual arguments and called
function need to use „*‟ operator along with formal arguments. Changing data through
an aaddress variable is known as indirect access and „*‟ is represented as indirection
operator.
@2020 Presented By Y. N. D. Aravind 20
Parameter Passing
Pass by value (or) call by value :-
Function call by value is the default way of calling a function in C
programming. Before we discuss function call by value, lets understand the
terminologies that we will use while explaining this:
Actual parameters: The parameters that appear in function calls.
Formal parameters: The parameters that appear in function declarations.
When we pass the actual parameters while calling a function then this is known
as function call by value. In this case the values of actual parameters are copied
to the formal parameters. Thus operations performed on the formal parameters
don’t reflect in the actual parameters.
Call By Value: In this parameter passing method, values of actual parameters
are copied to function’s formal parameters and the two types of parameters are
stored in different memory locations. So any changes made inside functions are
not reflected in actual parameters of caller.
@2020 Presented By Y. N. D. Aravind 21
Pass by Valur (or) Call By Value
Pass by reference (or) call by address :-
Before we discuss function call by reference, lets understand the terminologies
that we will use while explaining this:
Actual parameters: The parameters that appear in function calls.
Formal parameters: The parameters that appear in function declarations.
When we call a function by passing the addresses of actual parameters then this
way of calling the function is known as call by reference. In call by reference,
the operation performed on formal parameters, affects the value of actual
parameters because all the operations performed on the value stored in the
address of actual parameters. It may sound confusing first but the following
example would clear your doubts.
Call by Reference: Both the actual and formal parameters refer to same
locations, so any changes made inside the function are actually reflected in
actual parameters of caller.
@2020 Presented By Y. N. D. Aravind 22
Pass by Reference (or) Call by address
Thank You
@2020 Presented By Y. N. D. Aravind
Presented By
Y. N. D. ARAVIND
M.Tech, Dept of CSE
Newton’s Group Of Institutions, Macherla
23

More Related Content

What's hot

user defined function
user defined functionuser defined function
user defined functionKing Kavin Patel
 
C function presentation
C function presentationC function presentation
C function presentationTouhidul Shawan
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in CSyed Mustafa
 
Functions in C - Programming
Functions in C - Programming Functions in C - Programming
Functions in C - Programming GaurangVishnoi
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and typesmubashir farooq
 
Functions
FunctionsFunctions
FunctionsOnline
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in CPrabhu Govind
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)VC Infotech
 
Recursive Function
Recursive FunctionRecursive Function
Recursive FunctionHarsh Pathak
 
Functionincprogram
FunctionincprogramFunctionincprogram
FunctionincprogramSampath Kumar
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)SaraswathiTAsstProfI
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 

What's hot (20)

user defined function
user defined functionuser defined function
user defined function
 
C function presentation
C function presentationC function presentation
C function presentation
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Functions in C - Programming
Functions in C - Programming Functions in C - Programming
Functions in C - Programming
 
Functions
FunctionsFunctions
Functions
 
Function in c program
Function in c programFunction in c program
Function in c program
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
 
Functions
FunctionsFunctions
Functions
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Function in C program
Function in C programFunction in C program
Function in C program
 
4. function
4. function4. function
4. function
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 

Similar to Passing Parameters and Functions in C

Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptxMehul Desai
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfBoomBoomers
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfTeshaleSiyum
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdfTeshaleSiyum
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxMehakBhatia38
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functionsAlisha Korpal
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfstudy material
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfJAVVAJI VENKATA RAO
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functionsnikshaikh786
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++Muhammad Hammad Waseem
 

Similar to Passing Parameters and Functions in C (20)

Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptx
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
chapter-8-function-overloading.pdf
chapter-8-function-overloading.pdfchapter-8-function-overloading.pdf
chapter-8-function-overloading.pdf
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
C functions list
C functions listC functions list
C functions list
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Functions
FunctionsFunctions
Functions
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 

More from yndaravind

Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UMLyndaravind
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects yndaravind
 
The Object Model
The Object Model  The Object Model
The Object Model yndaravind
 
FILES IN C
FILES IN CFILES IN C
FILES IN Cyndaravind
 
Repetations in C
Repetations in CRepetations in C
Repetations in Cyndaravind
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in cyndaravind
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in Cyndaravind
 
Structure In C
Structure In CStructure In C
Structure In Cyndaravind
 
Strings part2
Strings part2Strings part2
Strings part2yndaravind
 
Arrays In C
Arrays In CArrays In C
Arrays In Cyndaravind
 
Strings IN C
Strings IN CStrings IN C
Strings IN Cyndaravind
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2yndaravind
 

More from yndaravind (14)

Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
The Object Model
The Object Model  The Object Model
The Object Model
 
OOAD
OOADOOAD
OOAD
 
OOAD
OOADOOAD
OOAD
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Repetations in C
Repetations in CRepetations in C
Repetations in C
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Bitwise Operators in C
Bitwise Operators in CBitwise Operators in C
Bitwise Operators in C
 
Structure In C
Structure In CStructure In C
Structure In C
 
Strings part2
Strings part2Strings part2
Strings part2
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 

Recently uploaded

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...Nguyen Thanh Tu Collection
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 

Recently uploaded (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Kamla Market (DELHI) 🔝 >àŒ’9953330565🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 

Passing Parameters and Functions in C

  • 1. @2020 Presented By Y. N. D. Aravind 1 Presented By Y. N. D. ARAVIND M.Tech, Dept of CSE Newton’s Group Of Institutions, Macherla 1
  • 2. Session Objectives Parameter Passing Passing Arrays to Functions Recursive Functions Function Components @2020 Presented By Y. N. D. Aravind 2 2
  • 3. A function is a block of code that performs a specific task. It has a name and it is reusable .It can be executed from as many different parts in a program as required, it can also return a value to calling program. All executable code resides within a function. It takes input, does something with it, then give the answer. A computer program cannot handle all the tasks by itself. It requests other program like entities called functions in C. We pass information to the function called arguments which specified when the function is called. A function either can return a value or returns nothing. Function is a subprogram that helps reduce coding. return_type function_name (argument list) { Set of statements – Block of code } @2020 Presented By Y. N. D. Aravind 3 3 Function in C
  • 4. Basically there are two reasons because of which we use functions 1. Writing functions avoids rewriting the same code over and over. For example - if you have a section of code in a program which calculates the area of triangle. Again you want to calculate the area of different triangle then you would not want to write the same code again and again for triangle then you would prefer to jump a "section of code" which calculate the area of the triangle and then jump back to the place where you left off. That section of code is called ..........„ function'. 2. Using function it becomes easier to write a program and keep track of what they are doing. If the operation of a program can be divided into separate activities, and each activity placed in a different function, then each could be written and checked more or less independently. Separating the code into modular functions also makes the program easier to design and understand. @2020 Presented By Y. N. D. Aravind 4 4 Why use Function
  • 5.  Once a function is defined and called, it takes some data from the calling function and returns a value to the called function.  When ever a function is called, control passes to the called function and working of the calling function is stopped.  When the execution of the called function is completed, a control returns back to the calling function and executes the next statement.  The values of actual arguments passed by the calling function are received by the formal arguments of the called function.  The number of actual and formal arguments should be the same. If the formal arguments are more than the actual arguments then the extra arguments appear as garbage.  The function operates on formal arguments and sends back the result to the calling function. @2020 Presented By Y. N. D. Aravind 5 5 How Function’s Work
  • 6. Def:- The function which is referring another function is called “calling function”. Def:- The function which is referenced by another function is called “called function” @2020 Presented By Y. N. D. Aravind 6 Calling Function and Called Function Actual Arguments and Formal Arguments Def:- The arguments of calling functions are called “actual arguments”. Def:- The arguments of called function are “formal arguments”. Local Variables and Global Variables Local variables:- The local variables are defined within the body of the function or the block. Other function cannot access these variables. Global variables:- Global variables are defined outside the main() function. Multiple functions can use them.
  • 7. @2020 Presented By Y. N. D. Aravind 7
  • 8. C provides library functions for performing some operations. These functions are present in the c library and they are predefined. For example sqrt() is a mathematical library function which is used for finding the square root of any number .The function scanf and printf() are input and output library function similarly we have strcmp() and strlen() for string manipulations. To use a library function we have to include some header file using the preprocessor directive #include. For example to use input and output function like printf() and scanf() we have to include stdio.h, for math library function we have to include math.h for string library string.h should be included. @2020 Presented By Y. N. D. Aravind 8 8 Library Function’s in C
  • 9. A user can create their own functions for performing any specific task of program are called user defined functions. To create and use these function we have to know these 3 elements. 1. Function Declaration 2. Function Definition 3. Function Call @2020 Presented By Y. N. D. Aravind 9 User defined Function’s in C
  • 10. 1. Function Declaration The program or a function that calls a function is referred to as the calling program or calling function. The calling program should declare any function that is to be used later in the program this is known as the function declaration or function prototype. 2. Function Definition The function definition consists of the whole description and code of a function. It tells that what the function is doing and what are the input outputs for that. A function is called by simply writing the name of the function followed by the argument list inside the parenthesis. Function definitions have two parts: Function Header The first line of code is called Function Header. int sum( int x, int y) It has three parts (i). The name of the function i.e. sum (ii). The parameters of the function enclosed in parenthesis (iii). Return value type i.e. int Function Body Whatever is written with in { } is the body of the function. 3. Function Call In order to use the function we need to invoke it at a required place in the program. This is known as the function call. @2020 Presented By Y. N. D. Aravind 10 User defined Function’s in C
  • 11. A function depending on whether arguments are present or not and whether a value is returned or not may belong to any one of the following categories: I. Functions with no arguments and no return values. II. Functions with arguments and no return values. III. Functions with arguments and return values. IV. Functions with no arguments and return values. @2020 Presented By Y. N. D. Aravind 11 Categories Of Function’s
  • 12. There is no data communication between the calling portion of a program and a called function block. The function is invoked bya calling environment by not passing any formal arguments and the function also does not return back any value to the caller. No Input No Output No data communication between functions @2020 Presented By Y. N. D. Aravind 12 Function’s with no arguments and no return values function1() { --------------------- --------------------- --------------------- function2(); /* function call*/ --------------------- --------------------- } function2() { --------------------- --------------------- --------------------- --------------------- --------------------- }
  • 13. #include<stdio.h> #include <conio.h> void maximum(); { int x,y,z,max; printf( “ Enter three Numbers n”); scanf(“%d%d%d”, &x,&y,&z); max = x; if(y > max) max = y; if(z > max) max = z; printf(“Maximum = %d n”,max); } void main() { clrscr(); maximum(); getch(); } @2020 Presented By Y. N. D. Aravind 13 Function’s with no arguments and no return values Input- Output Enter three Numbers 1 2 3 Maximum = 3
  • 14. The second type of user defined function passes some formal arguments to a function but the function does not return back any value to the caller. It is an one – way data communication between the calling portion of a program and a called function block. Values of arguments No return values One – way data communication between functions @2020 Presented By Y. N. D. Aravind 14 Function’s with arguments and no return values function1() { --------------------- --------------------- --------------------- function2(x); /* function call*/ --------------------- --------------------- } function2(a) { --------------------- --------------------- --------------------- --------------------- --------------------- }
  • 15. #include<stdio.h> #include <conio.h> void maximum(int, int, int); void main() { int x,y,z; clrscr(); printf( “ Enter three Numbers n”); scanf(“%d%d%d”, &x,&y,&z); maximum(x,y,z); getch(); } void maximum(int a, int b, int c) { int max; max = a; if(b > max) max = b; if(c > max) max = c; printf(“Maximum = %d n”,max); } @2020 Presented By Y. N. D. Aravind 15 Function’s with arguments and no return values Input- Output Enter three Numbers 1 2 3 Maximum = 3
  • 16. The third type of user defined function passes some formal arguments to a function from a calling portion of the progra and the computed value, if anyy, is transferred back to the caller. Data are communicated between the calling portion of a program and a called function block. Values of arguments Function results Two – way data communication between functions @2020 Presented By Y. N. D. Aravind 16 Function’s with arguments and with return values function1() { --------------------- --------------------- --------------------- function2(x); /* function call*/ --------------------- --------------------- } function2(a) { --------------------- --------------------- --------------------- --------------------- --------------------- return(z); }
  • 17. #include<stdio.h> #include <conio.h> int maximum(int x, int y, int z); void main() { int x,y,z,maxi; clrscr(); printf( “ Enter three Numbers n”); scanf(“%d%d%d”, &x,&y,&z); maxi = maximum(x,y,z); printf(“Maximum = %d n”,maxi); getch(); } int maximum(int x, int y, int z) { int max; max = x; if(y > max) max = y; if(z > max) max = z; return(max); } @2020 Presented By Y. N. D. Aravind 17 Function’s with arguments and with return values Input- Output Enter three Numbers 1 2 3 Maximum = 3
  • 18. The fourth type of user defined function, the function is invoked by a calling environment by not passing any formal arguments to a function but the computed value, if any, is transferred back to the caller. Data are communicated between the calling portion of a program and a called function block in one way. No Input Function results One – way data communication between functions @2020 Presented By Y. N. D. Aravind 18 Function’s with no arguments and return values function1() { --------------------- --------------------- --------------------- function2(); /* function call*/ --------------------- --------------------- } function2() { --------------------- --------------------- --------------------- --------------------- --------------------- return(z); }
  • 19. #include<stdio.h> #include <conio.h> int maximum(); void main() { int max; clrscr(); max = maximum(); printf(“Maximum = %d n”,max); getch(); } int maximum() { int x,y,z,max; printf( “ Enter three Numbers n”); scanf(“%d%d%d”, &x,&y,&z); max = x; if(y > max) max = y; if(z > max) max = z; return(max); } @2020 Presented By Y. N. D. Aravind 19 Function’s with no arguments and return values Input- Output Enter three Numbers 1 2 3 Maximum = 3
  • 20. Most programming languages have 2 strategies to pass parameters. They are i. pass by value ii. pass by reference Pass by value (or) call by value :- In this method calling function sends a copy of actual values to called function, but the changes in called function does not reflect the original values of calling function. Pass by reference (or) call by address :- In this method calling function sends address of actual values as a parameter to called function, called function performs its task and sends the result back to calling function. Thus, the changes in called function reflect the original values of calling function. To return multiple values from called to calling function we use pointer variables. Calling function needs to pass ..„&‟ operator along with actual arguments and called function need to use „*‟ operator along with formal arguments. Changing data through an aaddress variable is known as indirect access and „*‟ is represented as indirection operator. @2020 Presented By Y. N. D. Aravind 20 Parameter Passing
  • 21. Pass by value (or) call by value :- Function call by value is the default way of calling a function in C programming. Before we discuss function call by value, lets understand the terminologies that we will use while explaining this: Actual parameters: The parameters that appear in function calls. Formal parameters: The parameters that appear in function declarations. When we pass the actual parameters while calling a function then this is known as function call by value. In this case the values of actual parameters are copied to the formal parameters. Thus operations performed on the formal parameters don’t reflect in the actual parameters. Call By Value: In this parameter passing method, values of actual parameters are copied to function’s formal parameters and the two types of parameters are stored in different memory locations. So any changes made inside functions are not reflected in actual parameters of caller. @2020 Presented By Y. N. D. Aravind 21 Pass by Valur (or) Call By Value
  • 22. Pass by reference (or) call by address :- Before we discuss function call by reference, lets understand the terminologies that we will use while explaining this: Actual parameters: The parameters that appear in function calls. Formal parameters: The parameters that appear in function declarations. When we call a function by passing the addresses of actual parameters then this way of calling the function is known as call by reference. In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters. It may sound confusing first but the following example would clear your doubts. Call by Reference: Both the actual and formal parameters refer to same locations, so any changes made inside the function are actually reflected in actual parameters of caller. @2020 Presented By Y. N. D. Aravind 22 Pass by Reference (or) Call by address
  • 23. Thank You @2020 Presented By Y. N. D. Aravind Presented By Y. N. D. ARAVIND M.Tech, Dept of CSE Newton’s Group Of Institutions, Macherla 23