C++-练习-56

 题目:

编写通常接受一个参数(字符串的地址),并打印该字符串的函数。然而,如果提供了第二个参数(int类型),且该参数不为0,则该函数打印字符串的次数将为该函数被调用的次数(注意,字符串的打印次数不等于第二个参数的值,而等于函数被调用的次数)。

源代码:

#include <iostream>

void print(const char* st);
void print(const char* st, int size);

int main()
{
	print("hello world");
	print("hello world", 2);
	return 0;
}

void print(const char* st)
{
	std::cout << st << std::endl;
}
void print(const char* st, int size)
{
	if (size > 1)
		print(st, --size);
	std::cout << st << std::endl;
}

演示效果:

c17c3efd27aac6caf232c4dab0018088.png


如果朋友你感觉文章的内容对你有帮助,可以点赞关注文章和专栏以及关注我哈,嘿嘿嘿我会定期更新文章的,谢谢朋友你的支持哈

猜你喜欢

转载自blog.csdn.net/little_startoo/article/details/142908850