Function with two regular parameters and one parameter with default value : default arguments « Function « C++ Tutorial






#include <iostream> 
#include <cstring> 
using namespace std; 
 
void f(char *s1, char *s2, int len = 0); 
 
int main() 
{ 
  char str1[80] = "This is a test"; 
  char str2[80] = "0123456789"; 
 
  f(str1, str2, 5); 
  f(str1, str2); 
  return 0; 
} 
 
void f(char *s1, char *s2, int len) 
{ 
  cout << s1;
  cout << " " << len << " "; 
  cout << s2;
}
This is a test 5 0123456789This is a test 0 0123456789








7.6.default arguments
7.6.1.Demonstrate default arguments
7.6.2.Function with two regular parameters and one parameter with default value
7.6.3.Use two default parameter values
7.6.4.Ambiguous function call with function with default parameter value
7.6.5.Using multiple default parameter values: defaults for reference parameters
7.6.6.demonstrates missing and default arguments