Write a C Program to perform Call By Value and Call By Reference methods

By | March 19, 2017

C Program to perform Call By Value and Call By Reference methods


Write a C Program to perform Call By Value and Call By Reference methods. Here’s a Simple Program to perform Call By Value and Call By Reference methods in C Programming Language.


Call by Value


The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.

By default, C programming uses call by value to pass arguments. In general, it means the code within a function cannot alter the arguments used to call the function.


Below is the source code for C Program to perform Call By Value method which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :




Call by Reference


  • If data is passed by reference, a pointer to the data is copied instead of the actual variable as is done in a call by value. Because a pointer is copied, if the value at that pointers address is changed in the function, the value is also changed in main().
  • In call by reference, original value is modified because we pass reference (address).
  • Here, address of the value is passed in the function, so actual and formal arguments shares the same address space.Hence, value changed inside the function, is reflected inside as well as outside the function.

 


Below is the source code for C Program to perform Call By Reference method which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



Conclusion of Call By Value and Call By Reference :


Point Call by Value Call by Reference
Copy Duplicate Copy of Original Parameter is Passed Actual Copy of Original Parameter is Passed
Modification No effect on Original Parameter after modifying parameter in function Original Parameter gets affected if value of parameter changed inside function

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post.

Leave a Reply