首页 > 代码库 > 【*和&】复习

【*和&】复习

int main() { 
    int k = 12;//整数k,地址为x00CFFCA4
    int &c = k;//引用参数c,c及&c的值与k及&k相同
    int *w = &k;//指针参数指向k的地址,其本身地址为x00CFFC8C,指向k的地址为x00CFFCA4
    *w = 13;
    cout << "k1 = " << k << "           *k1 = " << &k << endl;
    cout << "w = " << w << "           *w = " << &w << endl;
    cout << "c = " << c << "           *c = " << &c << endl;
    cout << "k2 = " << k << "           *k2 = "<< &k << endl;

    system("pause");
    return 0;
}

技术分享

【应用举例】引用形参函数可避免不必要的拷贝。

【*和&】复习