为什么只有在直接打印一次字符串后,控制台才会显示调用函数打印的数组字符串

这是正常代码,但打印不出来

#include <iostream>
using namespace std;

int i = 0;
void show(const char* str, int sth = 0);

int main()
{
    char str[20] = "hello again,world!";
    show(str);
    show(str,2);
    return 0;
}

void show(const char* str, int sth)
{
    i++;
    if(sth == 0)
    {
        cout << str << endl;
    }
    else
    {
        for(int n=i; n>0; n--)
        {
            cout << str << endl;
        }
    }
}

打印结果如图图片说明

这是加了一个直接打印字符串的代码后

#include <iostream>
using namespace std;

int i = 0;
void show(const char* str, int sth = 0);

int main()
{
    char str[20] = "hello again,world!";
    show(str);
    show(str,2);
    return 0;
}

void show(const char* str, int sth)
{
    cout << "??什么问题??";
    i++;
    if(sth == 0)
    {
        cout << str << endl;
    }
    else
    {
        for(int n=i; n>0; n--)
        {
            cout << str << endl;
        }
    }
}

打印结果如图图片说明

在函数定义时把默认值也加入后,编译器就会检测出错误,如图:
图片说明
错误
图片说明

void show(const char* str, int sth)
->
void show(const char* str, int sth = 0)
否则sth是随机值,特别是可能是负数

导致无法输出