answersLogoWhite

0


Best Answer

Pass by value and pass by reference apply to functions that accept formal arguments. A formal argument may be a value or a reference. The function's caller uses actual arguments and the calling convention determines how an actual argument is assigned to the corresponding formal argument.

If the formal argument is a value, then the value of the actual argument is assigned to the formal argument.

If the formal argument is a reference, then the address of the actual argument is assigned to the formal argument.

The nett effect is that when you pass by reference, both the formal and actual arguments refer to the same object. Whereas when you pass by value, the formal argument is a copy of the actual argument.

Some languages, like C, do not support the notion of a reference argument and only use pass by value semantics. However, C does support the notion of a pointer data type which is a variable that can store a memory address. The value of a pointer is therefore a reference and passing a pointer by value is the same as passing by reference. This is because when a pointer value is assigned to another pointer, the address (the value of the pointer) is copied, thus the two pointers refer to the same object.

C++ evolved from C and uses the same pass by value semantic by default. However, C++ also has a dedicated reference type that allows native pass by reference semantics. A reference differs from a pointer in that a pointer is a variable and therefore requires memory of its own to store the address it refers to. Thus a pointer has an address and a value, just like any other variable. But a reference does not have its own address because a reference is simply an alias, an alternate name for an object in memory. In other words, the address of a reference is the address of the object it actually refers to, in the same way that Billy could be alternate name for an object named William; they are one and the same object by different names. A pointer is not an alias, it is a completely separate object. Another key difference is that a reference cannot be reassigned, it must be initialised at the point of declaration. In this respect it is similar to the behaviour of constant pointer. Finally, a reference can never refer to a non-existent object, whereas a pointer can. When a pointer is no longer required it must be nullified by assigning it the value zero.

User Avatar

Wiki User

โˆ™ 2015-01-21 12:47:46
This answer is:
User Avatar
Study guides

What is a programming language

What does DOS stand for

What is a software that is distributed for free

What is application software

โžก๏ธ
See all cards
3.77
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
26 Reviews

Add your answer:

Earn +20 pts
Q: Explain the difference between passing a piece of data by value and passing a piece of data by reference?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is meant by potential difference?

THE DIFFERENCE OF VOLTAGE FROM THE REFERENCE SOURCE TO THE LOAD OR A CERTAIN REFERENCE POINT AFTER PASSING THRU A CIRCUIT OR COMPONENTS.


What is the difference between spine and spline?

spine is reference direction and spline is curve, but in GSD spine is curve passing through plane.


Difference between dynamic binding and message passing in c plus plus?

what is the difference between message passing and dynamic binding


What is the difference between passing on and passing away?

To some people, there is no difference.. both mean dying. To others, the difference is that "passing away" means simply dying and "passing on" refers to going to the afterlife.


What is the difference between passing by value and passing by difference?

Passing by value is where you pass the actual value (be it an integer, an array, a struct, etc.) to a function. This means that the value must be copied before the function is called and therefore the value in the caller cannot be modified within the callee. Passing by reference is where a reference/pointer to a value is passed to a function. The reference often takes up less space than copying the actual value (particularly when the value is a struct or an array) and allows you to manipulate the value in the caller within the callee.


Difference between Dynamic binding and message passing in java?

difference between inheritaens & pholimorephezem in java


Explain the relationship between traits and heredity?

Heredity is the passing of traits to offspring


What is the difference between a blackout and passing out?

restigte stand 4 blackout & passing out stands 4 pass to anoyher level


Difference between allusion and illusion?

An allusion is an expression designed to call something to mind without mentioning it explicitly; an indirect or passing reference. An illusion is something that deceives by producing a false or misleading impression of reality.


What is message passing explain the advantages of message passing?

message passing is the way of exchanging information between systems or individuals,at d same time.advantage is that we can interact by getting all the necessary details


What is a difference between passing by value and passing arguments by reference in visual basic 6 procedures?

When we pass arguments my value, we are passing the value represented in the variable mentioned in the call, and not the variable itself. Therefore, any modifications made to that value will NOT be reflected in the variable mentioned in the call. Pass by reference, as the name suggests passes the reference of the variable mentioned in the procedure call. Any modifications made to the data of that variable is changed at the memory location of that data itself, and will be reflected in the variable itself, after the procedures completes.


Is a D a passing grade for 9th grade?

A D is a passing grade for 9th grade. It is the overall average of all grades that makes the difference between passing and repeating a grade.

People also asked