日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

g++默认参数_C ++默认参数| 查找输出程序| 套装2

發布時間:2025/3/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 g++默认参数_C ++默认参数| 查找输出程序| 套装2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

g++默認參數

Program 1:

程序1:

#include <iostream> using namespace std;int K = 10;int fun() {return K; } int sum(int X, int Y = fun()) {return (X + Y); }int main() {int A = 0;A = sum(5);cout << A << " ";K = 20;A = sum(5);cout << A << " ";return 0; }

Output:

輸出:

15 25

Explanation:

說明:

Here, we defined two functions fun() and sum().

在這里,我們定義了兩個函數fun()和sum() 。

The fun() function returns the value of global variable K. and function sum() take the second argument as a default argument, here we use fun() as a default value of the Y. If we modify the value of global variable K, then the default value will be changed automatically.?

fun()函數返回全局變量 K的值。 函數sum()將第二個參數作為默認參數,這里我們將fun()用作Y的默認值。 如果我們修改全局變量K的值,那么默認值將自動更改。

Now come to the function calls,

現在來看函數調用,

1st function call:

第一個函數調用:

A = sum(5);

Here, X = 5 and Y =10, because the value of K is 10 till now. then function return 15.?

在此, X = 5且Y = 10 ,因為到目前為止K的值為10。 然后函數返回15。

2nd function call:

第二次函數調用:

A = sum(5);

Before the second function call, we modify the value of the global variable K. The new value of K is 20. Then X = 5 and Y =20. Then function sum() return 25.

在第二個函數調用之前,我們修改全局變量K的值。 K的新值為20。然后X = 5,Y = 20。 然后函數sum()返回25。

Then the final output "15 25" will be printed on the console screen.

然后,最終輸出“ 15 25”將被打印在控制臺屏幕上。

Program 2:

程式2:

#include <iostream> #define NUM 10 + 20 using namespace std;int fun(int X = NUM) {return (NUM * NUM); }int main() {int RES = 0;RES = fun();cout << RES;return 0; }

Output:

輸出:

230

Explanation:

說明:

Here, we defined function fun() that takes macro NUM as a default value of the argument.

在這里,我們定義了函數fun() ,該函數將宏NUM作為參數的默認值。

Now, evaluate the expression used in the return statement,

現在,評估return語句中使用的表達式,

NUM*NUM 10+20*10+20 10+200+20 230

Then function fun() will return 230, and that will be printed on the console screen.

然后,函數fun()將返回230 ,并將其打印在控制臺屏幕上。

Recommended posts

推薦的帖子

  • C++ Default Argument | Find output programs | Set 1

    C ++默認參數| 查找輸出程序| 套裝1

  • C++ Switch Statement | Find output programs | Set 1

    C ++轉換語句| 查找輸出程序| 套裝1

  • C++ Switch Statement | Find output programs | Set 2

    C ++轉換語句| 查找輸出程序| 套裝2

  • C++ goto Statement | Find output programs | Set 1

    C ++ goto語句| 查找輸出程序| 套裝1

  • C++ goto Statement | Find output programs | Set 2

    C ++ goto語句| 查找輸出程序| 套裝2

  • C++ Looping | Find output programs | Set 1

    C ++循環| 查找輸出程序| 套裝1

  • C++ Looping | Find output programs | Set 2

    C ++循環| 查找輸出程序| 套裝2

  • C++ Looping | Find output programs | Set 3

    C ++循環| 查找輸出程序| 套裝3

  • C++ Looping | Find output programs | Set 4

    C ++循環| 查找輸出程序| 套裝4

  • C++ Looping | Find output programs | Set 5

    C ++循環| 查找輸出程序| 套裝5

  • C++ Arrays | Find output programs | Set 1

    C ++數組| 查找輸出程序| 套裝1

  • C++ Arrays | Find output programs | Set 2

    C ++數組| 查找輸出程序| 套裝2

  • C++ Arrays | Find output programs | Set 3

    C ++數組| 查找輸出程序| 套裝3

  • C++ Arrays | Find output programs | Set 4

    C ++數組| 查找輸出程序| 套裝4

  • C++ Arrays | Find output programs | Set 5

    C ++數組| 查找輸出程序| 套裝5

翻譯自: https://www.includehelp.com/cpp-tutorial/default-argument-find-output-programs-set-2.aspx

g++默認參數

總結

以上是生活随笔為你收集整理的g++默认参数_C ++默认参数| 查找输出程序| 套装2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。