8. A) Differentiate between call by value and call by reference using suitable examples.
Answer:-
Parameters | Call by value | Call by reference |
---|---|---|
Definition | While 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. |
Arguments | In this method, a copy of the variable is passed. | In this method, a variable itself is passed. |
Effect | Changes 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 value | Does 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 variable | Values of variables are passed using a straightforward method. | Pointer variables are required to store the address of variables. |
Value modification | Original value not modified. | The original value is modified. |
Memory Location | Actual and formal arguments will be created in different memory location | Actual and formal arguments will be created in the same memory location |
Safety | Actual 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. |
Default | Default 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. |