SlideShare a Scribd company logo
3
Most read
4
Most read
8
Most read
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

PDF
Bayes Belief Networks
PPTX
SECONDARY WASTEWATER TREATMENT.pptx
PPTX
Ai chatbot ppt.pptx
PPTX
Pointer in c
PPTX
Maxima & Minima of Calculus
PPT
Basic concept of OOP's
PPTX
application of differential equations
Bayes Belief Networks
SECONDARY WASTEWATER TREATMENT.pptx
Ai chatbot ppt.pptx
Pointer in c
Maxima & Minima of Calculus
Basic concept of OOP's
application of differential equations

What's hot (20)

PPT
RECURSION IN C
PPT
Function overloading(c++)
PPTX
Recursive Function
PPTX
Functions in C
PPTX
Nested loops
PPTX
Dynamic memory allocation in c
PDF
Operators in c programming
PPTX
Queue ppt
PDF
Introduction to c++ ppt
PPTX
Data types in C
PPTX
PDF
Applications of stack
PPT
PPT
Operator Overloading
PPTX
Tuple in python
PPTX
Structure in C
PPTX
INLINE FUNCTION IN C++
PPTX
classes and objects in C++
RECURSION IN C
Function overloading(c++)
Recursive Function
Functions in C
Nested loops
Dynamic memory allocation in c
Operators in c programming
Queue ppt
Introduction to c++ ppt
Data types in C
Applications of stack
Operator Overloading
Tuple in python
Structure in C
INLINE FUNCTION IN C++
classes and objects in C++
Ad

Viewers also liked (12)

PPTX
Parameter passing to_functions_in_c
PDF
Pointers and call by value, reference, address in C
PPTX
C++ programming function
PDF
Core java 5 days workshop stuff
PPT
Functions
PPTX
Functions in C++
PPT
16717 functions in C++
 
PPT
C++ Function
PPT
FUNCTIONS IN c++ PPT
PPT
Functions in C++
PPTX
functions of C++
PPT
Basics of C programming
Parameter passing to_functions_in_c
Pointers and call by value, reference, address in C
C++ programming function
Core java 5 days workshop stuff
Functions
Functions in C++
16717 functions in C++
 
C++ Function
FUNCTIONS IN c++ PPT
Functions in C++
functions of C++
Basics of C programming
Ad

Similar to Call by value (20)

PPTX
Call by value
PPTX
Function in c
PPTX
DOCX
PPTX
Fundamentals of functions in C program.pptx
PPTX
C function
PPTX
CHAPTER 6
PPTX
Function in c program
DOC
Unit 4 (1)
PPTX
Function in C program
PPTX
Functions (Computer programming and utilization)
PPT
Functions and pointers_unit_4
PPTX
Functions in C
PPT
Unit iv functions
PPTX
C Programming Language Part 7
PPTX
Functionincprogram
PPTX
Functions
PPT
Functions and pointers_unit_4
PPT
6.3 c-Functions.ppt
PPTX
unit_2.pptx
Call by value
Function in c
Fundamentals of functions in C program.pptx
C function
CHAPTER 6
Function in c program
Unit 4 (1)
Function in C program
Functions (Computer programming and utilization)
Functions and pointers_unit_4
Functions in C
Unit iv functions
C Programming Language Part 7
Functionincprogram
Functions
Functions and pointers_unit_4
6.3 c-Functions.ppt
unit_2.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.