Developer community
0 votes
asked by Expert (13.2k points) 29 44 63 | 1.4k views

1 Answer

0 votes
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.


#include <stdio.h>

void swap(int x, int y) {

int t;

t = x;

x = y;

y = t;

} int main() {

int m = 10, n = 20;

printf("Before executing swap m=%d n=%d\n", m, n);

swap(m, n);

printf("After executing swap m=%d n=%d\n", m, n);

return 0;


Before executing swap m=10 n=20

After executing swap m=10 n=20


In the main function, value of variables m, n are not changed though they are passed to function 'swap'. Swap function has a copy of m, n and hence it can not manipulate the actual value of arguments passed to it.
answered by Guru (39.1k points) 11 24 38

Related questions

0 votes
1 answer
asked by keem Expert (13.2k points) 29 44 63 | 1.5k views
0 votes
1 answer
0 votes
1 answer
+1 vote
3 answers
0 votes
1 answer
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers


10.7k users

3,754 questions
4,046 answers
10,709 users