任何人都可以告诉下面的代码有什么问题吗?
int main () {
return main();
}
Run Code Online (Sandbox Code Playgroud)
我测试过,它编译正确.它一直在运行.现场背后的诀窍呢?
#include <iostream>
#include <cstdlib>
int main() {
cout << "!!!Hello World!!!" << endl;
system("pause");
return main();
}
Run Code Online (Sandbox Code Playgroud)
上面的工作,但它硬编码main()
,是否有一个神奇的变量来获得当前的运行功能?
我有一个带有静态变量"count"的递归函数.函数递增递增计数,因为它有文件范围,当我第二次调用foo()时,count仍然等于5.是否有一种技术在第二次调用foo()之前将count重置为0?
基本上,我不希望计数有文件范围,但我希望它通过不同的迭代保留其值.
我能想到的一种方法是在foo()中使用一个参数来初始化foo().比如foo(int count).但还有另一种方式吗?
#include <iostream>
using namespace std;
void foo()
{
static int count = 0;
if(count<5)
{
count++;
cout<<count<<endl;
foo();
}
else
{
cout<<"count > 5"<<endl;
}
}
int main()
{
foo(); //increment count from 0 to 5
foo(); //count is already at 5
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在学习编程C
.你能解释一下这里为什么没有打印出来吗 提前致谢.
#include <stdio.h>
int main (void)
{
char a[]="abcde";
printf ("%s", a);
}
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
int main()
{
printf("Hi!\nWelcome!\nThis is an expression based calculator\ndeveloped by Sankasuvra Bhattacharya\n");
printf("that performs arithmetic operations on\ntwo numbers.\n");
float num1;
float num2;
float ans = 0.0;
char symbol;
char ask;
printf("Please type the expression you want to calculate: ");
if(scanf("%f%1s%f",&num1,&symbol,&num2) != 3)
{
printf("\nInvalid input! Please try again...\n\n");
/* want to restart main() again here */
}
else {
switch(symbol) {
case '+' : ans = num1 + num2;
break;
case '-' : ans = num1 - num2; …
Run Code Online (Sandbox Code Playgroud) 我正在重新学习C++.我以前是一个相当的菜鸟,但我再次讨论基础知识,并希望更进一步.我的主要问题是,在主循环结束时,是否有一种方法可以再次调用该函数,而不是通过返回0结束程序.所以沿着这样的方向:
........
return main;
}
Run Code Online (Sandbox Code Playgroud)