Skip to main content

Posts

Showing posts with the label Call by Value and Call by Reference

Call by Value and Call by Reference( pass by value and pass by reference)

There are two ways to pass arguments/parameters to function calls -- call by value and call by reference.. The major difference between call by value and call by reference is that in call by value a copy of actual arguments is passed to respective formal arguments. While, in call by reference the location (address) of actual arguments is passed to formal arguments, hence any change made to formal arguments will also reflect in actual arguments. In C, all function arguments are passed "by value". The calling and called functions do not share any memory -- they have their own copy and the called function cannot directly alter a variable in the calling function; it can only alter its private, temporary copy. There are cases we need call by reference. 1.The called function communicates to the calling function only through return statement and return statement can only send one value back to the calling function. If there are more than one value we want to alter, call by