Call by Reference and Address in C++

Hello guys!! welcome to my new post. I am going to discuss about functions and its working in C++. In my previous post we learned about call by value. So now we will learn other two methods. Here we go!!

Call By Address!!!

         
For this method, we use asterisk(*) symbol in declaration and definition part. It is also called pointer variable. You can also get detailed information about pointer in this given link :
 CLICK HERE
      
Program will run from declaration then definition and then to the call part. In declaration part we assume (int *, int *). It means we will take two variables which converts into pointer variables. Next step is in definition part, in this part we assume x and y variables which converts into pointers. We know that pointer contains the address(&) of other variable. When we subtract both variables, we also need to write "*" symbol. In calling part, we use another two variables "&a" , "&b" which is address of assuming variables so value of both assuming variable stores in this variables. So we declare with "&" symbol and one variable "X" which stores the output of assuming variables. 
 
When we call the function, it will go from declaration to definition part and subtracts both and will return to the main function. In main function, we took two values of both pointer variables and this values points to &a and &b respectively and process on it, Then answer is stored in the other variable "X". Next step is to print the value so it will print.

Call By Reference!!!


             In call by reference we need to use "&" symbol as a reference in the declaration and definition part. Process will be same as the above method. But in this method we just have to call from reference variables.
So this is it. My next post will be based on inline and friend functions.

Until we meet next time keep coding !!!


Twitter: @NewAgeInformers

Instagram: @new_age_informers_



Comments