What is the output of this C code?
#include
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
exit(0);
printf("%d\n", i);
return reverse(i++);
}
a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow
View Answer
Answer:d
. What is the value of i and j in the below code?
#include <stdio.h>
int x = 0;
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
int f()
{
if (x == 0)
return x + 1;
else
return x - 1;
}
int g()
{
return x++;
}
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
View Answer
Answer:c
还有这个
你编译的时候不报错吗?我很是好奇。我记得c语言代码是在main函数中调用方法时,方法要么定义在main函数之前,要么在main函数之前申明,不然是会报错的吧。。。
这种情况可以不用在入口函数前声明,编译器会自动找到在入口函数后面定义的函数,但是从编程的可读性来讲,不建议这么写。