I have a snippet of code where C++ functions are declared with default argument of char and int type.
#include <iostream>
using namespace std;
int print(char c = '*', int num = 10);
int print(char c, int num)
{
for (int i = 0; i < num; i++)
{
cout << c << endl ;
}
cout << endl;
return 0;
}
int main()
{
int rep;
char letter;
cout << "Enter a character : ";
cin >> letter;
cout << "Enter the number of times it has to repeat : ";
cin >> rep;
print(letter, rep);
print(rep);
print(letter);
return 0;
}
There is no output for print(rep);
even though default argument for character is given. Any idea why this is happening?
I tried to use default arguments, but default argument of char is not working as intended and there is no intended character output for that.