SlideShare a Scribd company logo
1 of 14
Download to read offline
CSE101-Lec#14
Function Call
Outline
©LPU CSE101 C Programming
• Function call
– Passing arguments by value
– Passing arguments by reference
Formal Arguments and
Actual Arguments
©LPU CSE101 C Programming
• Argument: An argument is an expression which is
passed to a function by its caller in order for the
function to perform its task.
arguments: The arguments that are
• Actual
passed in a function call are called actual
arguments. These arguments are defined in the
calling function.
• Formal arguments: The formal arguments are the
parameters/arguments in a function declaration.
Formal arguments are a copy of the actual
arguments.
#include <stdio.h>
void sum(int i, int j, int k); /*function prototype*/
int main()
{
int a = 5;
sum(3, 2 * a, a); // actual arguments
return 0;
}
void sum(int i, int j, int k)//formal arguments
{
int s;
s = i + j + k;
printf("sum is %d", s);
}
©LPU CSE101 C Programming
Methods of passing arguments
©LPU CSE101 C Programming
• There are two ways to call a function/to pass
arguments to a function:
1. Call by value
2. Call by reference
Call by Value
©LPU CSE101 C Programming
• Call by value
– In this method the values of actual arguments are
copied to the formal arguments of the function.
– Changes in function do not effect original
– Use when function does not need to modify
argument
• Avoids accidental changes
– The method of passing arguments by value is
know as call by value
#include <stdio.h>
int callByValue(int n); // prototype / declaration
int main( void )
{
int number = 5; // initialize number
printf("The original value of number is %d", number);
callByValue(number); // pass number by value
printf( "nThe new value of number is %dn", number );
} // end main
int callByValue( int n )
{
return n*n*n; //cube local variable n and return value
}
©LPU CSE101 C Programming
The original value of number is 5
The new value of number is 5
Call by reference
©LPU CSE101 C Programming
• The address of actual argument are copied to
the formal arguments.
• The called function uses the address to refer
to the actual location.
• Changes made by the function are effective
when the control returns to the calling
function.
– If we want to make changes even in the actual
arguments, then we use call by address
Address of variable
int i=3;
If we want to
©LPU CSE101 C Programming
print the address of variable:
#include<stdio.h>
void main()
{
int i=3;
printf("address of i=%d", &i);
printf("value of i =%d", i);
}
Pointers
©LPU CSE101 C Programming
• A variable which stores address of another
variable
• Example:
int *p;
int i;
p= &i;
*p gives value at address stored in p.
 int *p means p is containing an address of
variable on which an integer is stored
Calling Functions by Reference
©LPU CSE101 C Programming
• Call by reference with pointer arguments
– Pass address of argument using & operator
– Allows you to change actual location in memory
• * operator
– Used as alias/nickname for variable inside of function
void double( int *number )
{
*number = 2 * ( *number );
}
– *number used as nickname for the variable passed
#include <stdio.h>
void callByReference(int *nPtr); //function prototype
int main( void )
{
int number = 5;
printf("The original value of number is %d", number);
callByReference( &number ); //pass address of number
printf("nThe new value of number is %dn", number);
} // end main
//calculate cube of *nPtr; actually modifies number in main
void callByReference( int *nPtr )
{
*nPtr = *nPtr * *nPtr * *nPtr; //cube *nPtr
}
©LPU CSE101 C Programming
The original value of number is 5
The new value of number is 125
Header Files-Review
©LPU CSE101 C Programming
• Header files
– Contain function prototypes for library functions
– <stdlib.h> , <math.h> , etc
– Load with #include <filename>
"filename.h"
#include <math.h>
• Custom header files
– Create file with functions
– Save as filename.h
– Load in other files with #include
– Reuse functions
• Example #include<square.h>
cse101@lpu.co.in
Next Topic:
Recursive Functions
©LPU CSE101 C Programming

More Related Content

Similar to CSE101-Lec#14 [function call].pdf

UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptxNagasaiT
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...kushwahashivam413
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxvanshhans21102005
 
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
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in CRAJ KUMAR
 
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
 
how to reuse code
how to reuse codehow to reuse code
how to reuse codejleed1
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 

Similar to CSE101-Lec#14 [function call].pdf (20)

UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
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
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
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
 
4th unit full
4th unit full4th unit full
4th unit full
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
 
Functions
FunctionsFunctions
Functions
 
Function
FunctionFunction
Function
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 

More from AbdulWahab672

A798057369_21039_13_2018_Structure & Organization-Anima
A798057369_21039_13_2018_Structure & Organization-AnimaA798057369_21039_13_2018_Structure & Organization-Anima
A798057369_21039_13_2018_Structure & Organization-AnimaAbdulWahab672
 
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdf
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdfA798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdf
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdfAbdulWahab672
 
clinical needs, medical devices, medical
clinical needs, medical devices, medicalclinical needs, medical devices, medical
clinical needs, medical devices, medicalAbdulWahab672
 
Various anatomical structures of the body h
Various anatomical structures of the body hVarious anatomical structures of the body h
Various anatomical structures of the body hAbdulWahab672
 
This if a topic fir the students of biomedical engineering
This if a topic fir the students of biomedical engineeringThis if a topic fir the students of biomedical engineering
This if a topic fir the students of biomedical engineeringAbdulWahab672
 
Ph electrode nots for biomedical engineering
Ph electrode nots for biomedical engineeringPh electrode nots for biomedical engineering
Ph electrode nots for biomedical engineeringAbdulWahab672
 
Bomedical engineering faculty if scince and technilogy
Bomedical  engineering faculty if scince and technilogyBomedical  engineering faculty if scince and technilogy
Bomedical engineering faculty if scince and technilogyAbdulWahab672
 
L5-6. Cellular organization.ppt
L5-6. Cellular organization.pptL5-6. Cellular organization.ppt
L5-6. Cellular organization.pptAbdulWahab672
 
L9. Nervous System.ppt
L9. Nervous System.pptL9. Nervous System.ppt
L9. Nervous System.pptAbdulWahab672
 
L7. Nucleic Acids.ppt
L7. Nucleic Acids.pptL7. Nucleic Acids.ppt
L7. Nucleic Acids.pptAbdulWahab672
 
حجره و وظیفه آن.docx
حجره و وظیفه آن.docxحجره و وظیفه آن.docx
حجره و وظیفه آن.docxAbdulWahab672
 

More from AbdulWahab672 (13)

A798057369_21039_13_2018_Structure & Organization-Anima
A798057369_21039_13_2018_Structure & Organization-AnimaA798057369_21039_13_2018_Structure & Organization-Anima
A798057369_21039_13_2018_Structure & Organization-Anima
 
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdf
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdfA798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdf
A798057369_21039_13_2018_Structure & Organization-Animal cell-Dr. Mishra.pdf
 
clinical needs, medical devices, medical
clinical needs, medical devices, medicalclinical needs, medical devices, medical
clinical needs, medical devices, medical
 
Various anatomical structures of the body h
Various anatomical structures of the body hVarious anatomical structures of the body h
Various anatomical structures of the body h
 
This if a topic fir the students of biomedical engineering
This if a topic fir the students of biomedical engineeringThis if a topic fir the students of biomedical engineering
This if a topic fir the students of biomedical engineering
 
Ph electrode nots for biomedical engineering
Ph electrode nots for biomedical engineeringPh electrode nots for biomedical engineering
Ph electrode nots for biomedical engineering
 
Bomedical engineering faculty if scince and technilogy
Bomedical  engineering faculty if scince and technilogyBomedical  engineering faculty if scince and technilogy
Bomedical engineering faculty if scince and technilogy
 
L5-6. Cellular organization.ppt
L5-6. Cellular organization.pptL5-6. Cellular organization.ppt
L5-6. Cellular organization.ppt
 
L9. Nervous System.ppt
L9. Nervous System.pptL9. Nervous System.ppt
L9. Nervous System.ppt
 
L7. Nucleic Acids.ppt
L7. Nucleic Acids.pptL7. Nucleic Acids.ppt
L7. Nucleic Acids.ppt
 
L8.Tissues.ppt
L8.Tissues.pptL8.Tissues.ppt
L8.Tissues.ppt
 
حجره و وظیفه آن.docx
حجره و وظیفه آن.docxحجره و وظیفه آن.docx
حجره و وظیفه آن.docx
 
GL PPT.pptx
GL PPT.pptxGL PPT.pptx
GL PPT.pptx
 

Recently uploaded

Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Sheetaleventcompany
 
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...Delhi Call girls
 
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncr
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi NcrCall Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncr
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncrnoida100girls
 
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥anilsa9823
 
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779Best VIP Call Girls Noida Sector 73 Call Me: 8448380779
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779Delhi Call girls
 
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Delhi Call girls
 
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceanilsa9823
 
Dubai Call Girls Will Eats O528786472 Call Girls Dubai Moore
Dubai Call Girls Will Eats O528786472 Call Girls Dubai MooreDubai Call Girls Will Eats O528786472 Call Girls Dubai Moore
Dubai Call Girls Will Eats O528786472 Call Girls Dubai Moorehf8803863
 
Dubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnm
Dubai Call Girls Centerfold O525547819 Call Girls Dubai CfnmDubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnm
Dubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnmkojalkojal131
 
Call girls in Jalandhar 8264406502 escort service in Jalandhar
Call girls in Jalandhar 8264406502 escort service in JalandharCall girls in Jalandhar 8264406502 escort service in Jalandhar
Call girls in Jalandhar 8264406502 escort service in JalandharSheetaleventcompany
 
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Delhi Call girls
 
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...Delhi Call girls
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)Delhi Call girls
 
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)Delhi Call girls
 
Call girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in JaipurCall girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in Jaipurrahul222jai
 

Recently uploaded (19)

Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
Maya❤️Call girls in Mohali ☎️7435815124☎️ Call Girl service in Mohali☎️ Mohal...
 
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
 
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncr
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi NcrCall Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncr
Call Girls In Vasant Kunj ☎✔ 9871031762 ☎✔ Russion Escorts Service In Delhi Ncr
 
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service  🧥
CALL ON ➥8923113531 🔝Call Girls Vikas Nagar Lucknow best Female service 🧥
 
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779Best VIP Call Girls Noida Sector 73 Call Me: 8448380779
Best VIP Call Girls Noida Sector 73 Call Me: 8448380779
 
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
Best VIP Call Girls Noida Sector 49 Call Me: 8448380779
 
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
Best VIP Call Girls Noida Sector 62 Call Me: 8448380779
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service
 
Dubai Call Girls Will Eats O528786472 Call Girls Dubai Moore
Dubai Call Girls Will Eats O528786472 Call Girls Dubai MooreDubai Call Girls Will Eats O528786472 Call Girls Dubai Moore
Dubai Call Girls Will Eats O528786472 Call Girls Dubai Moore
 
Dubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnm
Dubai Call Girls Centerfold O525547819 Call Girls Dubai CfnmDubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnm
Dubai Call Girls Centerfold O525547819 Call Girls Dubai Cfnm
 
Call girls in Jalandhar 8264406502 escort service in Jalandhar
Call girls in Jalandhar 8264406502 escort service in JalandharCall girls in Jalandhar 8264406502 escort service in Jalandhar
Call girls in Jalandhar 8264406502 escort service in Jalandhar
 
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
Best VIP Call Girls Noida Sector 63 Call Me: 8448380779
 
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Mayur Vihar Delhi >༒8448380779 Escort Service
 
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf Cyber City Gurgaon >༒8448380779 Escort Service
 
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
call girls in Indirapuram (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service...
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 68 (Gurgaon)
 
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Huda City Centre Gurgaon >༒8448380779 Escort Service
 
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)
Enjoy Night ≽ 8448380779 ≼ Call Girls In Gurgaon Sector 52 (Gurgaon)
 
Call girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in JaipurCall girls in Jaipur 9358660226 escort service in Jaipur
Call girls in Jaipur 9358660226 escort service in Jaipur
 

CSE101-Lec#14 [function call].pdf

  • 2. Outline ©LPU CSE101 C Programming • Function call – Passing arguments by value – Passing arguments by reference
  • 3. Formal Arguments and Actual Arguments ©LPU CSE101 C Programming • Argument: An argument is an expression which is passed to a function by its caller in order for the function to perform its task. arguments: The arguments that are • Actual passed in a function call are called actual arguments. These arguments are defined in the calling function. • Formal arguments: The formal arguments are the parameters/arguments in a function declaration. Formal arguments are a copy of the actual arguments.
  • 4. #include <stdio.h> void sum(int i, int j, int k); /*function prototype*/ int main() { int a = 5; sum(3, 2 * a, a); // actual arguments return 0; } void sum(int i, int j, int k)//formal arguments { int s; s = i + j + k; printf("sum is %d", s); } ©LPU CSE101 C Programming
  • 5. Methods of passing arguments ©LPU CSE101 C Programming • There are two ways to call a function/to pass arguments to a function: 1. Call by value 2. Call by reference
  • 6. Call by Value ©LPU CSE101 C Programming • Call by value – In this method the values of actual arguments are copied to the formal arguments of the function. – Changes in function do not effect original – Use when function does not need to modify argument • Avoids accidental changes – The method of passing arguments by value is know as call by value
  • 7. #include <stdio.h> int callByValue(int n); // prototype / declaration int main( void ) { int number = 5; // initialize number printf("The original value of number is %d", number); callByValue(number); // pass number by value printf( "nThe new value of number is %dn", number ); } // end main int callByValue( int n ) { return n*n*n; //cube local variable n and return value } ©LPU CSE101 C Programming The original value of number is 5 The new value of number is 5
  • 8. Call by reference ©LPU CSE101 C Programming • The address of actual argument are copied to the formal arguments. • The called function uses the address to refer to the actual location. • Changes made by the function are effective when the control returns to the calling function. – If we want to make changes even in the actual arguments, then we use call by address
  • 9. Address of variable int i=3; If we want to ©LPU CSE101 C Programming print the address of variable: #include<stdio.h> void main() { int i=3; printf("address of i=%d", &i); printf("value of i =%d", i); }
  • 10. Pointers ©LPU CSE101 C Programming • A variable which stores address of another variable • Example: int *p; int i; p= &i; *p gives value at address stored in p.  int *p means p is containing an address of variable on which an integer is stored
  • 11. Calling Functions by Reference ©LPU CSE101 C Programming • Call by reference with pointer arguments – Pass address of argument using & operator – Allows you to change actual location in memory • * operator – Used as alias/nickname for variable inside of function void double( int *number ) { *number = 2 * ( *number ); } – *number used as nickname for the variable passed
  • 12. #include <stdio.h> void callByReference(int *nPtr); //function prototype int main( void ) { int number = 5; printf("The original value of number is %d", number); callByReference( &number ); //pass address of number printf("nThe new value of number is %dn", number); } // end main //calculate cube of *nPtr; actually modifies number in main void callByReference( int *nPtr ) { *nPtr = *nPtr * *nPtr * *nPtr; //cube *nPtr } ©LPU CSE101 C Programming The original value of number is 5 The new value of number is 125
  • 13. Header Files-Review ©LPU CSE101 C Programming • Header files – Contain function prototypes for library functions – <stdlib.h> , <math.h> , etc – Load with #include <filename> "filename.h" #include <math.h> • Custom header files – Create file with functions – Save as filename.h – Load in other files with #include – Reuse functions • Example #include<square.h>