What is call by value and call by reference?



Suraj Said

+0 -0

Call by value: In this method, the value of the argument is passed to the function. This means that the function receives a copy of the argument, and any changes made to the argument within the function do not affect the original variable.
Call by reference: In this method, the memory address of the argument is passed to the function. This means that the function receives a pointer to the argument, and any changes made to the argument within the function are reflected in the original variable.



Shreya Said

+0 -0

Call by value and call by reference are two methods of passing parameters to functions in C. In call by value, the values of the actual parameters (the variables in the caller function) are copied to the formal parameters (the variables in the called function). Any changes made to the formal parameters do not affect the actual parameters. In call by reference, the addresses of the actual parameters are passed to the function as pointers. Any changes made to the formal parameters using the pointers are reflected in the actual parameters. Call by reference allows the function to modify the original data, while call by value preserves the original data.



Vikas Said

+0 -0

Call by value involves passing a copy of the actual parameters value to the function, where modifications to the parameter inside the function do not affect the original value outside the function. Call by reference involves passing the memory address (reference) of the actual parameter to the function, allowing the function to directly access and modify the original value outside the function.



Submit Your Response