本文介绍了按引用呼叫和按地址呼叫有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按引用呼叫和按地址呼叫有什么区别?我们可以说以下两个程序代表按引用概念进行调用吗?

程序1 ................................................... ......

what is the difference between call by reference and call by address? can we say the following two programs represents the call by reference concept?

Program-1..........................................................

int main()
{
    void fun(int *x);
    
    int a=10;
    cout<<a<<endl;
    
    fun(&a);
    
    cout<<a;
    getch();
    return 0;
}

void fun(int *x)
{
     (*x)++;
}





程序2 .................................................. .........................





Program-2........................................................................

int main()
{
    void fun(int& x);
    
    int a=10;
    cout<<a<<endl;
    
    fun(a);
    
    cout<<a;
    getch();
    return 0;
}

void fun(int& x)
{
     x++;
}



[edit]添加了代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

void fun(int x, int& y, int* z);
int main()
   {
   int a = 10;
   int b = 20;
   int c = 30;
   fun(a, b, &c);
   cout << a << b << c;	
   return 0;
   }
void fun(int x, int& y, int* z)
   {
   x++;
   y++;
   *z++;
   }




这篇关于按引用呼叫和按地址呼叫有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 10:27