KnowledgeBoat Logo
|

Computer Applications

What is the principal reason for passing arguments by reference ? In a function call, what all data items can be passed by reference ?

User Defined Methods

5 Likes

Answer

The principal reason for passing arguments by reference is that we want the modifications done by the called method to reflect back to the original variables (i.e., actual parameters). For example, a method that swaps the values of two variables. In this case, we will pass an object containing the two integers to the method so that the swapped variables are visible in the calling method.

The reference data types — objects and arrays, are passed by reference.

Answered By

3 Likes


Related Questions