Users Online

· Guests Online: 143

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

49 C Program to Illustrate Pass by Value

This C Program illustrates pass by value. This program is used to explain how pass by value function works. Pass by Value: In this method, the value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. In pass by value, the changes made to formal arguments in the called function have no effect on the values of actual arguments in the calling function.
Here is source code of the C Program to illustrate pass by value. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to Illustrate Pass by Value.
*/
#include <stdio.h>

void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}

int main()
{
int num1 = 10, num2 = 20;

printf("Before swapping num1 = %d num2 = %d\n", num1, num2);
swap(num1, num2);
printf("After swapping num1 = %d num2 = %d \n", num2, num1);
return 0;
}

Output:
$ cc pgm43.c
$ a.out
Before swapping num1 = 10 num2 = 20
After swapping num1 = 20 num2 = 10

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.90 seconds
10,807,669 unique visits