the output I'm getting for the given code is "0" even though I initialized the value of c as "1"...can somebody explain it... Why is the value of "C" changing in the following code??
#include <iostream>
using namespace std;
int c=1; // global initialized 'c' as 1..
long long f(long long n){
if(n==6){
return 2;
}
else{
c=c+1;
f(n-2);
}
}
int main()
{
long long n,ans,p;
cin>>n;
ans=f((2*n)-2);
cout<<c; //printing out the value of 'c'
return 0;
}
最佳答案
因为 c 的值在下面的代码中被更改:
else{
c=c+1;
f(n-2);
}
关于c++ - 为什么以下代码中 "C"的值会发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31168949/