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