2015-04-26 79 views
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; 
} 

如果我们在cRef中传递地址,则地址应该乘以三倍。价值如何倍增三倍?通过引用地址通过问题

回答

0

你有一个引用变量作为参数,因此变量将被改变,而不是地址本身。参考变量是实际变量的别名,因此对其进行的更改将反映对您的案例中的原始变量进行的更改

+0

尚不清楚!我是一个新手请相应清除 – Rizvi

+0

我认为如果你只是Google'd“引用变量C++”会更好,但我会尝试解释。也许你对于声明运营商是什么感到困惑。所以有一些运营商具有双重含义。例如,“&”符号可用于提取左值的地址,但也可用于声明引用变量。我在回答中增加了一些内容 –