Loading....
Coupon Accepted Successfully!

 

Example Of Pass By Value

#include <stdio.h>

 

/* function declaration goes here.*/

void swap( int p1, int p2 );

 

int main()

{

int a = 10;

int b = 20;

 

printf(“Before: Value of a = %d and value of b = %d\n”, a, b );

swap( a, b );

printf(“After: Value of a = %d and value of b = %d\n”, a, b );

}

void swap( int p1, int p2 )

{

int t;

 

t = p2;

p2 = p1;

p1 = t;

printf(“Value of a (p1) = %d and value of b(p2) = %d\n”, p1, p2 );

}

Here is the result produced by the above example. Here the values of a and b remain unchanged before calling swap function and after calling swap function.

Before: Value of a = 10 and value of b = 20

Value of a (p1) = 20 and value of b(p2) = 10

After: Value of a = 10 and value of b = 20





Test Your Skills Now!
Take a Quiz now
Reviewer Name