c++ - Pass by Reference Address passing issue -
this question has answer here:
- pass reference / value in c++ 6 answers
#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 "<<num<<endl; return 0; } void callbyreference (int & cref) //funciton definition { cref=cref*cref*cref; }
if passing address in cref address should multiplied thrice. how value multiplied thrice?
you have reference variable argument, variable altered , not address itself. reference variable alias actual variable , changes made reflect in changes made original variable in case
Comments
Post a Comment