0
#include<iostream>
using namespace std;

void callByReference (int &);    //Function Prototype

int main()
{
  int num;                         //Variable Declaration
  cout<<"Enter number"; 
  cin>>num;
  callByReference(num);             //Function Definition
  cout<<"Number after triple is "<<num<<endl;
  return 0;
}

void callByReference (int & cRef)   //Funciton Definition
{
  cRef=cRef*cRef*cRef;
}

If we are passing address in cRef then address should be multiplied thrice. How the value is multiplied thrice?

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
Rizvi
  • 69
  • 5

1 Answers1

0

You have a reference variable as an argument, thus the variable will be altered and not the address itself. A reference variable is an alias for the actual variable and thus changes made to it will reflect in changes made to the original variable in your case

Amateur Math Guy
  • 199
  • 2
  • 3
  • 12
  • Not clear yet! I am a newbie please clear accordingly – Rizvi Apr 26 '15 at 10:57
  • I think it would be better if you just Google'd "reference variables c++", but I'll try and explain. Maybe you are confused as to what a declaration operator is. So there are some operators that have dual meanings. For example the "&" symbol can be used to extract the address of an lvalue, but it is also used to declare reference variables. I've added a little more to my answer – Amateur Math Guy Apr 26 '15 at 11:00