answersLogoWhite

0


Best Answer

Passing an argument by value means that the method that receives the argument can not change the value of the argument. Passing an argument by reference means that the method that receives the argument can change the value of the incoming argument, and the argument may be changed in the orignal calling method.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of passing an argument by value?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the name given to the technique whereby a function argument can be modified by passing a pointer to the argument?

Call_by_reference


What argument passes in a method that will reference the content and can change the variable in the method?

That is called passing an argument by reference.


Does C even have pass by reference?

Strictly speaking, no. All arguments in C are passed by value. However, when the argument being passed is a memory address, although the address itself is passed by value, we're effectively passing the object that resides at that address -- by reference. Thus when a function's formal argument is a pointer variable (of any type), then it can be taken as read that the function is using the pass by reference semantic rather than the pass by value semantic. Nevertheless, it is important to keep in mind that the formal argument is assigned a copy of the actual argument and is therefore being passed by value.


What are the advantages of pass by reference as compared to pass by value?

Call by reference, particularly when applied to objects, because call by value automatically invokes an object's copy constructor, which is seldom desirable when passing objects into functions.


Where to use overloading?

Default arguments are often considered to be optional arguments, however a default argument is only optional in the sense that the caller need not provide a value for it. The function must still instantiate the argument and must assign the appropriate value to it so, insofar as the function is concerned, the argument is not optional. To implement a function with a truly optional argument, we can define two overloads of that function, one that accepts the optional argument (without specifying a default value) and one that does not accept the argument. In this way we can define two different implementations, one that uses the argument and one that does not. void f (); // implementation that does not use the argument void f (int); // implementation that does use the argument In many cases, a default argument incurs no significant overhead over that of overloading. Thus we'd only use overloading to implement an optional argument where there is a significant overhead incurred by a default argument. Even so, we must also be aware that by eliminating the overhead within the function itself we may simply be passing that overhead back to the callers, because some or all of them would then have to decide which overload to call, resulting in code duplication that would likely be best handled by the function itself.

Related questions

What do you call an argument that only has a copy of the arguments value and will not be affected by the method?

That is called passing an argument by value.


What is mean by'pass by value'?

If you mean 'call by value' then, it means a method of passing argument to a function in c++. In this a copy of argument is passed to function and changes are not reflected.


What does Excel do if you do not include an optional argument?

If you do not include an optional argument, Excel will use the default value for that argument.


What is the name given to the technique whereby a function argument can be modified by passing a pointer to the argument?

Call_by_reference


What argument passes in a method that will reference the content and can change the variable in the method?

That is called passing an argument by reference.


Does C even have pass by reference?

Strictly speaking, no. All arguments in C are passed by value. However, when the argument being passed is a memory address, although the address itself is passed by value, we're effectively passing the object that resides at that address -- by reference. Thus when a function's formal argument is a pointer variable (of any type), then it can be taken as read that the function is using the pass by reference semantic rather than the pass by value semantic. Nevertheless, it is important to keep in mind that the formal argument is assigned a copy of the actual argument and is therefore being passed by value.


Where do you use no argument no return in c function?

Where there is no need to return any type of value from a function


What are the advantages of pass by reference as compared to pass by value?

Call by reference, particularly when applied to objects, because call by value automatically invokes an object's copy constructor, which is seldom desirable when passing objects into functions.


Why you use pointers?

Because you can produce fast and efficient code. Function arguments are passed "by value", and so you can't change the original value of the argument, but if you use pointers, you can.


Why use pointer?

Because you can produce fast and efficient code. Function arguments are passed "by value", and so you can't change the original value of the argument, but if you use pointers, you can.


Where to use overloading?

Default arguments are often considered to be optional arguments, however a default argument is only optional in the sense that the caller need not provide a value for it. The function must still instantiate the argument and must assign the appropriate value to it so, insofar as the function is concerned, the argument is not optional. To implement a function with a truly optional argument, we can define two overloads of that function, one that accepts the optional argument (without specifying a default value) and one that does not accept the argument. In this way we can define two different implementations, one that uses the argument and one that does not. void f (); // implementation that does not use the argument void f (int); // implementation that does use the argument In many cases, a default argument incurs no significant overhead over that of overloading. Thus we'd only use overloading to implement an optional argument where there is a significant overhead incurred by a default argument. Even so, we must also be aware that by eliminating the overhead within the function itself we may simply be passing that overhead back to the callers, because some or all of them would then have to decide which overload to call, resulting in code duplication that would likely be best handled by the function itself.


When passing an argument by reference the module can modify the argument in the calling part of the program?

Yes, when passing an argument by reference, changes to the argument made within the module will directly affect the original variable in the calling part of the program. This is because the reference to the original variable's memory address is passed to the module, allowing it to modify the variable directly.