Computer Science: Function: Call by Value: Calling of Function

Get unlimited access to the best preparation resource for IAS : fully solved questions with step-by-step explanation- practice your way to success.

Download PDF of This Page (Size: 293K)

Image of Call by value

Image of Call by Value

Call by Value

Calling of Function

The function can be called using either of the following methods:

Image of Calling of Function

Image of Calling of Function

Consider the following program which will swap the value of two variables using the method call-by-value.

# include < iostream.h>

void swap (int, int).

void main ()


int a, b.

cin > > a > > b.

swap (a, b).

cout < < a < < b < < “\n”.


void swap (int c, int d)


int t.

t = c.

c = d.

d = t.

cout < < c < < d < < “\n”.


  • The variables a and b are called actual parameters.

  • When calling the function swap (). the value of a is passed onto c and value of b is passed onto d.

  • Here c and d are called formal parameters.

Image of actual and formal parameters

Image of Actual and Formal Parameters

In the function swap (), the value are swapped but this change will not be implemented to actual parameters.

Input 5 6

Input 6 5

5 6

Developed by: