Mega Code Archive

 
Categories / C++ Tutorial / Function
 

Function with two regular parameters and one parameter with default value

#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