Differentiate between call by value and call by reference using suitable examples.

8. A) Differentiate between call by value and call by reference using suitable examples.

Answer:-

ParametersCall by valueCall by reference
DefinitionWhile calling a function, when you pass values by copying variables, it is known as “Call By Values.”While calling a function, in programming language instead of copying the values of variables, the address of the variables is used it is known as “Call By References.
ArgumentsIn this method, a copy of the variable is passed.In this method, a variable itself is passed.
EffectChanges made in a copy of a variable never modify the value of the variable outside the function.Change in the variable also affects the value of the variable outside the function.
Alteration of valueDoes not allow you to make any changes in the actual variables.Allows you to make changes in the values of variables by using function calls.
Passing of variableValues of variables are passed using a straightforward method.Pointer variables are required to store the address of variables.
Value modificationOriginal value not modified.The original value is modified.
Memory LocationActual and formal arguments
will be created in different
memory location
Actual and formal arguments
will be created in the same
memory location
SafetyActual arguments remain
safe as they cannot be modified
accidentally.
Actual arguments are not
Safe. They can be
accidentally modified, so you need to handle argument operations carefully.
DefaultDefault in many programming
languages like C++.PHP. Visual Basic NET, and C#.
It is supported by most
programming languages like JAVA, but
not as default.

Leave a Reply

Your email address will not be published. Required fields are marked *