C++默认值参数

#include iostreamusing namespace std;int sum(int a, int b = 20) {int result;result = a + b;return (result);

编程学习网为您整理以下代码实例,主要实现:C++默认值参数,希望可以帮到各位朋友。

#include <iostream>

using namespace std;

int sum(int a, int b = 20) {
   int result;
   result = a + b;

   return (result);
}
int main () {
   // local variable declaration:
   int a = 100;
   int b = 200;
   int result;

   // calling a function to add the values.
   result = sum(a, b);
   cout << "Total value is :" << result << endl;

   // calling a function again as follows.
   result = sum(a);
   cout << "Total value is :" << result << endl;

   return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐