【发布时间】:2013-01-26 10:17:03
【问题描述】:
#include<stdio.h>
#include<conio.h>
int f(int & ,int );//function prototype
main()
{
int x,p=5; //p is initialized to 5
x=f(p,p);
printf("\n Value is : %d",x);//print the value of x
getch();
}
int f (int & x, int c)
{
c=c-1;
if (c==0) return 1;
x=x+1;
return f(x,c) * x; //recursion
}
输出:6561
谁能解释一下程序的流程 这个问题来自我无法理解的大门。似乎该函数是用 p = 5 的值调用的。它在函数 f 中被 int &x 捕获,问题就在这里。是值,即 5 存储在 x 中还是 x 的地址中。
【问题讨论】:
-
这不是 C,
int &语法是 C++。 -
即使我昨天出现在 Gate 并且无法理解这个问题。希望有人能解释一下。
-
@user2060893 stackoverflow.com/questions/6877052/…看看这个问题