SlideShare a Scribd company logo
1 of 9
CALL BY VALUE
&
CALL BY REFERNCE
TOPIC:
PRESENTED BY
G.DHARANI
THERE ARE TWO WAYS IN WHICH WE CAN
PASS ARGUMENTS TO THE FUNCTION
CALL BY VALUE
 Value of actual arguments passed to the
formal arguments.
Any change made in the formal arguments
does not effect the actual arguments.
When function is called it does not affect the
actual contents of the actual arguments.
#include <stdio.h>
void call_by_value(int x)
{
printf("Inside call_by_value x = %d before adding 10.n", x);
x += 10;
printf("Inside call_by_value x = %d after adding 10.n", x);
}
int main() {
int a=10;
printf("a = %d before function call_by_value.n", a);
call_by_value(a);
printf("a = %d after function call_by_value.n", a);
return 0;
}
EXAMPLE PROGRAM
OUTPUT OF THE PROGRAM
a = 10 before function call_by_value.
Inside call_by_value x = 10 before
adding 10.
Inside call_by_value x = 20 after
adding 10.
a = 10 after function call_by_value.
Actual and Formal arguments
 Arguments passed to the function during function call
are known as actual arguments
 The arguments we use during a function definition are
known as formal arguments.
For a function call to be valid the type, order and number of
actual and formal arguments must always be same.
 Value of each of the actual arguments in the calling function
is copied into the formal arguments of the called function.
Changes made have no effect on the values of actual
arguments in the calling function.
Concept of Actual and Formal
arguments
CALL BY VALUE CALL BY REFERENCE
CALLING FUNCTION SENDS COPIES TO
DATA.
THE FORMAL PARAMETERS ARE
ORDINARY VARIABLES.
ATMOST ONLY ONE VALUES CAN BE SENT
BACK TO THE CALLING FUNCTION.
ACTUAL PARAMETERS ARE AFFECTED BY
CHANGES MADE WITHIN THE FUNCTION.
CALLING FUNCTION SENDS ADDRESS OF
DATA.
THE FORMAL PARAMETERS ARE POINTER
VARIABLE.
SEVERAL RESULTS CAN BE SENT BACK
TO THE CALLING FUNCTION.
DIRECT CHANGES ARE MADE TO THE
ACTUAL PARAMETERS.
Call by value

More Related Content

What's hot (20)

Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
String functions in C
String functions in CString functions in C
String functions in C
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C if else
C if elseC if else
C if else
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Strings
StringsStrings
Strings
 
Structure in C
Structure in CStructure in C
Structure in C
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Array in c
Array in cArray in c
Array in c
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 

Viewers also liked

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
 
Core java 5 days workshop stuff
Core java 5 days workshop stuffCore java 5 days workshop stuff
Core java 5 days workshop stuffRajiv Gupta
 
Functions
FunctionsFunctions
FunctionsOnline
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 

Viewers also liked (11)

Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
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
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Core java 5 days workshop stuff
Core java 5 days workshop stuffCore java 5 days workshop stuff
Core java 5 days workshop stuff
 
Functions
FunctionsFunctions
Functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
functions of C++
functions of C++functions of C++
functions of C++
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 

Similar to Call by value

Similar to Call by value (20)

Call by value
Call by valueCall by value
Call by value
 
Function in c
Function in cFunction in c
Function in c
 
Function in c
Function in cFunction in c
Function in c
 
Array Cont
Array ContArray Cont
Array Cont
 
C function
C functionC function
C function
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Unit iv functions
Unit  iv functionsUnit  iv functions
Unit iv functions
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Functions
FunctionsFunctions
Functions
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
6.3 c-Functions.ppt
6.3 c-Functions.ppt6.3 c-Functions.ppt
6.3 c-Functions.ppt
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.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
 
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
 

Call by value

  • 1. CALL BY VALUE & CALL BY REFERNCE TOPIC: PRESENTED BY G.DHARANI
  • 2. THERE ARE TWO WAYS IN WHICH WE CAN PASS ARGUMENTS TO THE FUNCTION
  • 3. CALL BY VALUE  Value of actual arguments passed to the formal arguments. Any change made in the formal arguments does not effect the actual arguments. When function is called it does not affect the actual contents of the actual arguments.
  • 4. #include <stdio.h> void call_by_value(int x) { printf("Inside call_by_value x = %d before adding 10.n", x); x += 10; printf("Inside call_by_value x = %d after adding 10.n", x); } int main() { int a=10; printf("a = %d before function call_by_value.n", a); call_by_value(a); printf("a = %d after function call_by_value.n", a); return 0; } EXAMPLE PROGRAM
  • 5. OUTPUT OF THE PROGRAM a = 10 before function call_by_value. Inside call_by_value x = 10 before adding 10. Inside call_by_value x = 20 after adding 10. a = 10 after function call_by_value.
  • 6. Actual and Formal arguments  Arguments passed to the function during function call are known as actual arguments  The arguments we use during a function definition are known as formal arguments.
  • 7. For a function call to be valid the type, order and number of actual and formal arguments must always be same.  Value of each of the actual arguments in the calling function is copied into the formal arguments of the called function. Changes made have no effect on the values of actual arguments in the calling function. Concept of Actual and Formal arguments
  • 8. CALL BY VALUE CALL BY REFERENCE CALLING FUNCTION SENDS COPIES TO DATA. THE FORMAL PARAMETERS ARE ORDINARY VARIABLES. ATMOST ONLY ONE VALUES CAN BE SENT BACK TO THE CALLING FUNCTION. ACTUAL PARAMETERS ARE AFFECTED BY CHANGES MADE WITHIN THE FUNCTION. CALLING FUNCTION SENDS ADDRESS OF DATA. THE FORMAL PARAMETERS ARE POINTER VARIABLE. SEVERAL RESULTS CAN BE SENT BACK TO THE CALLING FUNCTION. DIRECT CHANGES ARE MADE TO THE ACTUAL PARAMETERS.