五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

c++ 傳值 傳引用 與 傳指針

2023-02-15 13:36 作者:__牛油果__  | 我要投稿

#include <iostream>using namespace std;
// 函數(shù)聲明void swap(int x, int y);
int main (){ ? // 局部變量聲明 ? int a = 100; ? int b = 200;
// ? cout << " Before main, a is : " << a << endl;// ? cout << " Before main, b is : " << b << endl;
? /* 調(diào)用函數(shù)來交換值 */ ? swap(a, b);
// ? 單純的傳值,只在調(diào)用的函數(shù)中改變值,原來的值并沒有改變: ? cout << " Just copied a copy to the formal parameter, a is the same a, b is the same b"<< endl; ? cout << " After ?main, a is : " << a << endl; ? cout << " After ?main, b is : " << b << endl;
? return 0;}
// 函數(shù)定義void swap(int x, int y){ ? int temp; ? cout << "--------Before swap --------:"<<endl; ? cout << x <<endl; ? cout << y <<endl; ? temp = x; /* 保存地址 x 的值 */ ? x = y; ? ?/* 把 y 賦值給 x ?*/ ? y = temp; /* 把 x 賦值給 y ?*/ ? cout << "--------After ?swap --------:"<<endl; ? cout << x <<endl; ? cout << y <<endl; ? return;}
// 1 傳值,傳遞實參,即單純的傳值,從內(nèi)存使用的角度來說,傳遞實參,則會將數(shù)據(jù)拷貝過去(創(chuàng)建了副本),// ? 即swap()對傳入的數(shù)據(jù)做任何修改,都不會影響main()。// 2 傳引用// ? 作為形參的引用會指向形參,類似于指針,調(diào)用函數(shù)后,實現(xiàn)了真正的交換。swap()和main()都交換了。// 3 傳指針// ? 類似于傳引用// https://www.runoob.com/cplusplus/passing-parameters-by-references.html

c++ 傳值 傳引用 與 傳指針的評論 (共 條)

分享到微博請遵守國家法律
伽师县| 盐山县| 饶阳县| 东城区| 宜君县| 南雄市| 东山县| 镇巴县| 宜州市| 鄢陵县| 辽源市| 肥乡县| 曲水县| 全州县| 射阳县| 揭东县| 通化市| 江华| 岳阳市| 宜丰县| 通海县| 诏安县| 大理市| 将乐县| 教育| 双牌县| 宁波市| 兖州市| 怀柔区| 慈溪市| 佛坪县| 永修县| 上虞市| 长乐市| 汨罗市| 伊通| 云梦县| 靖边县| 普兰店市| 塔城市| 杭锦后旗|