SlideShare a Scribd company logo

Call by value

Dharani G
Dharani G
1 of 9
Download to read offline
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.

Recommended

Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++Sachin Yadav
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming LanguageMahantesh Devoor
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programmingprogramming9
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 

More Related Content

What's hot

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Data types in C
Data types in CData types in C
Data types in C
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Strings in C
Strings in CStrings in C
Strings in C
 
C functions
C functionsC functions
C functions
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 

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

Call by value
Call by valueCall by value
Call by valueDharani G
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Digvijaysinh Gohil
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4MKalpanaDevi
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
This assignment contains an empty function to evaluate- Your job is to.docx
This assignment contains an empty function to evaluate- Your job is to.docxThis assignment contains an empty function to evaluate- Your job is to.docx
This assignment contains an empty function to evaluate- Your job is to.docxrochellej1
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4Saranya saran
 
6.3 c-Functions.ppt
6.3 c-Functions.ppt6.3 c-Functions.ppt
6.3 c-Functions.pptMrVMNair
 
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
 

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
 
This assignment contains an empty function to evaluate- Your job is to.docx
This assignment contains an empty function to evaluate- Your job is to.docxThis assignment contains an empty function to evaluate- Your job is to.docx
This assignment contains an empty function to evaluate- Your job is to.docx
 
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
 

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.