Advertisements
Advertisements
प्रश्न
Answer the following in brief. Give a reason/example wherever applicable.
Explain Call by Value and Call by Reference.
स्पष्ट करा
कारण सांगा
Advertisements
उत्तर
Call by Value:
In call by value, a copy of the actual value is passed to the method. Any changes made inside the method do not affect the original variable.
- Example:
void update(int x)
{
x = 20;
}
- Reason: The method receives a separate copy of the value.
Call by Reference:
In call by reference, the reference of the original data is passed to the method. Changes made inside the method affect the original data.
- Example: Passing an object reference to a method can modify the object's data.
- Reason: The method accesses the same memory location of the origina
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
