我的朋友们有问题.问题是没有初始化变量如何打印0到10?
我知道使用初始化使用for循环打印的方法
for(int i=0;i<=10;i++) {
cout<<i;
}
Run Code Online (Sandbox Code Playgroud)
这int i = 0是初始化的.那么如何在不初始化相关变量的情况下打印0到10个值?有可能吗?
Luc*_*ore 11
cout << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10";
cout << "012345678910";
Run Code Online (Sandbox Code Playgroud)
void myPrint(int x)
{
cout << x;
if ( x < 10 )
myPrint( x+1 );
}
myPrint(0);
Run Code Online (Sandbox Code Playgroud)
template<int x> void foo()
{
foo<x-1>();
cout << x << '\n';
}
template<> void foo<0>()
{
cout << 0 << '\n';
}
foo<10>();
Run Code Online (Sandbox Code Playgroud)
Rob*_*obᵩ 11
你的朋友应该学会更准确地指出他们的问题.
int i; // i is not initialized
i = 0; // i is assigned
for( ;i<=10;i++)
{
cout<<i;
}
Run Code Online (Sandbox Code Playgroud)