What is the difference of pass by value and pass by reference?

Asked by Last Modified  

13 Answers

Follow 0
Answer

Please enter your answer

Computer science

Pass by value:----just suppose u have a note copy(fair copy) . Your friend ask you to give your copy. You just xerox your fair copy and give to your friend. After that he/she edit on your xerox copy. Show there will be no change in original copy. Same in function also value is copy and all the...
read more
Pass by value:----just suppose u have a note copy(fair copy) . Your friend ask you to give your copy. You just xerox your fair copy and give to your friend. After that he/she edit on your xerox copy. Show there will be no change in original copy. Same in function also value is copy and all the work done on copy value(xerox copy). Call by reference:--- You just given your original copy. so if any change done is done on your original copy. mean u pass the address of original variable. So all change done on original one(note copy). read less
Comments

Software Developer and Trainer with 10 years of experience

Both Pass by Value(Call by value) and Pass by Reference(Call by reference/address) are the two methods to call a function. Let me explain them so that we can easily identify the difference. In pass by value, You call a function by directly passing the value of the arguments. The values will be...
read more
Both Pass by Value(Call by value) and Pass by Reference(Call by reference/address) are the two methods to call a function. Let me explain them so that we can easily identify the difference. In pass by value, You call a function by directly passing the value of the arguments. The values will be copied by the called function and all statements in that function will work on those copied values only. Thus this method of calling will not modify originally passed values. In pass by reference, You call a function by passing the references (memory address) of original values. This reference will be received in pointers by called functions. Through the pointers, the called function work on the values that are stored in those memory addresses. Thus this method of calling will modify the original values itself. In simple, If you call by value, the passed values will be duplicated and called function will work on that duplicate values. So original values will not be affected. If you call by reference, the passed addresses will be directly accessed through pointers. This cause modification of original data. read less
Comments

B.Tech(c.s)

In the pass by value to passing just a copy of variable and any changes in the value will not reflect in original one. Where as in the call by reference you pass the address of the variable and changes will reflect in the original one.
Comments

C, linux kernel

Pass by value will just copy the value of the variable to function argument whereas, pass by reference will send the address of the variable to the function argument. So, the changes you do in the function will be reflected in the caller function in case of pass by reference.
Comments

Every variable that you create in your code requires some memory (on RAM) to store its value. For example, when you create an integer in C++, the system reserves 2 bytes in RAM to store the value of the integer. Every variable can be located internally by the system using an address called memory-address...
read more
Every variable that you create in your code requires some memory (on RAM) to store its value. For example, when you create an integer in C++, the system reserves 2 bytes in RAM to store the value of the integer. Every variable can be located internally by the system using an address called memory-address (it is a binary number). If you want to pass a variable as a functions argument, there are two ways, it can be done: 1) Pass by value. Here the value of the variable being passed is copied into the function's parameter variable. Example: Suppose we have a function void add(int a, int b); In main function, we call the function such as: int x = 5, y = 6; add(x, y); Now here, when the function is called, the values of x and y (5 and 6) are copied into the function's parameters a and b. This means that if you change the values of a and b inside the function's code, then x and y are not affected. 2) Pass by reference When we pass a variable by reference the address of the variable being passed is copied into the function's parameter. Example: Suppose we have a function void add(int &a, int &b); In main function, if we call it using the same code: int x = 5, y = 6; add(x,y); then, only the reference of x and y will be passed to a and b instead of copying the values. Hence, a and b will use the same memory location of x and y to access or change its values. This means that if you change the value of a inside the function, then it will change the value of variable x of main function. Similarly changing value of b will change y of main. Long answer, but I hope I have managed to explain you the difference. Feel free to contact me if you have any doubts. :) read less
Comments

BE(all subject) and 12th biology,maths,tamil,english,physics,chemistry.

Passing by reference : the called functions' parameter will be the same as the callers' passed argument, Pass by value : the called functions' parameter will be a copy of the callers' passed argument.
Comments

Make you shine in programming

Say I want to share a web page with you. If I tell you the URL, I'm passing by reference. You can use that URL to see the same web page I can see. If that page is changed, we both see the changes. If you delete the URL, all you're doing is destroying your reference to that page - you're not deleting...
read more
Say I want to share a web page with you. If I tell you the URL, I'm passing by reference. You can use that URL to see the same web page I can see. If that page is changed, we both see the changes. If you delete the URL, all you're doing is destroying your reference to that page - you're not deleting the actual page itself. If I print out the page and give you the printout, I'm passing by value. Your page is a disconnected copy of the original. You won't see any subsequent changes, and any changes that you make (e.g. scribbling on your printout) will not show up on the original page. If you destroy the printout, you have actually destroyed your copy of the object - but the original web page remains intact read less
Comments

Software Devloper

In pass by value approach, the called function creates another copies of the variables passes as arguments. In this approach, the values of the original variables remain unchanged. However, we come across situations where we need to change the values of the original variables. Then the values may b passed...
read more
In pass by value approach, the called function creates another copies of the variables passes as arguments. In this approach, the values of the original variables remain unchanged. However, we come across situations where we need to change the values of the original variables. Then the values may b passed by reference read less
Comments

B.E., M.Tech

1) In pass by value, the value of the arguments (actual parameters) are copied to the formal parameters whereas in pass by reference, the address of the arguments (actual parameters) are copied to the formal parameters. 2) In pass by value, changes to the formal parameters won't alter the value of...
read more
1) In pass by value, the value of the arguments (actual parameters) are copied to the formal parameters whereas in pass by reference, the address of the arguments (actual parameters) are copied to the formal parameters. 2) In pass by value, changes to the formal parameters won't alter the value of the arguments (actual parameters) whereas in pass by reference, changes to the formal parameters alter the value of the arguments (actual parameters) read less
Comments

Using pass by value we pass the values using variables where as pass by reference we pass adresses of variables.
Comments

View 11 more Answers

Related Questions

Is coaching needed for class 12 Economics?
It depends on you choice if you have need then join if not then it is not necessary for you.
Bhakti
0 0
7
What is the main difference between pBR322 and pBR310 ?
Plasmid pBR322 has been completely sequenced. It characterizes pBR322 in terms of its restriction sites i.e. exact length of every fragment can be calculated. These fragments can serve as DNA markers...
Abdur Rahman W.
0 1
7
what is c programing?
C is high level and general purpose programming language used for portable and firware applications ,intended for writing sys software
Smu

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

The Evolution Of The Intel x86 Architecture
Throughout this book, we rely on many concrete examples of computer design and implementation to illustrate concepts and to illuminate trade-offs. Most of the time, the book relies on examples from two...

What Are Register Variables?
Registers are faster than memories to access. Hence when we declare a variable with a registerkey word, the compiler gets to know that the variable can be put to registers. Now whether the variables will...

Drag And Its Classifications
Introduction Drag is the enemy of flight and its cost. One group of those forces is aerodynamic forces that split into two forces: Lift force or lift, and Drag force or drag. A pre-requisite to aircraft...

Starting Career in Android Development
Starting career in Android has become trouble free now. There is a lot of content available online to start learning Android. Just type “Android development” in Google and you will be flooded...

Sources of Energy: Quick notes-Science, Class 10, CBSE. (Also a major topic in Energy Engineering)
Conventional Sources of Energy: Fossil fuels: Most Common, Non-Renewable, Causes pollution. Thermal power plants: Fuel burnt-Heating water to steam-drive turbines-produce electricity. Hydro Power...

Recommended Articles

MBA, Medicine and engineering are the three main professional courses in India. Engineering is still one of the highly sorted after professional courses in the under graduate level, while MBA is favoured as a preferred post graduate course. To shine in these courses, one needs to work and study hard. Engineering as a...

Read full article >

According to a recent survey conducted by the NCAER (National Council of Advanced Economic Research), engineering is the most sought after course in India. Some engineering courses are offered as BE or Bachelor of Engineering while some as Bachelor in Technology or B.Tech. Since engineering is a professional course, the...

Read full article >

E-learning is not just about delivering lessons online. It has a much broader scope that goes beyond manual paper or PowerPoint Presentations. To understand the reach of E-learning and how the whole process works in developing the Educational system, we will discuss a few points here. Let us find out how this new learning...

Read full article >

With the mushrooming of international and private schools, it may seem that the education system of India is healthy. In reality, only 29% of children are sent to the private schools, while the remaining head for government or state funded education. So, to check the reality of Indian education system it is better to look...

Read full article >

Looking for BTech Tuition ?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you