Filter by Tags

Pass by value and pass by reference

Votes

1

1 0
This Question is asked to:

Give an example to explain the concept of pass by value and pass by reference in C

Ravinder Singh
Posted on : Mon, Feb 19, 2018
Views : 58
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (1)


0

1.call by value : call by value original value can not be changed or modified . when  you passed  value to the function it is locally stored by the function  parametter in memory location 

example :

void swap(int a, int b)

{

int temp;

temp=a;

a=b;

b= temp;

}

void main()

{

int a= 100, b=200;

swap(a,b)

printf("\n value of a%d",a);

printf("\n value of b%d",b);

getch();

}

2.call by reference : this method  copy address of argument into function as a argument. address of the value passed in function ,actual and formal argument share same address  space. any value changed in function is reflected inside or as well as outside function.

example:

void swap(int*a,int*b)

{

int temp;

temp=*a;

*a=*b;

*b=temp;

}

void main()

{

int a=100,b=200;

swap(&a,&b)

printf("\n value of a%d",a);

printf("\n  value of b%d",b);

getch();

}

 

 

 

Jaspreet kaur
Tue, Feb 20, 2018
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp