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;
}

本文标题为:C++默认值参数

上一篇: C++标准输出流
下一篇: C++按值调用

基础教程推荐