以下两个函数有什么区别?

时间:2016-05-11 11:59:14

标签: c++ unix g++

我熟悉c而不是c ++的新手。 以下两个函数有什么区别?这两个程序在功能上如何相同?实际上如何在场景1中传递地址并修改值而不取消引用变量。

情景1

    void duplicate (int& a, int& b, int& c)
    {
    a*=2; 
    b*=2;
    c*=2;
    }

    int main ()
    {
    int x=1, y=3, z=7;
    duplicate (x, y, z); 
    cout << "x=" << x << ", y=" << y << ", z=" << z;
    return 0;
    }

情景2

    #include <iostream>
    using namespace std;

    void duplicate (int *a, int *b, int *c) 
    {
    *a*=2;
    *b*=2;
    *c*=2;
    }

    int main ()
    {
    int x=1, y=3, z=7;
    duplicate (&x, &y, &z);
    cout << "x=" << x << ", y=" << y << ", z=" << z << endl;
    return 0;
    }

0 个答案:

没有答案
相关问题