c++ - Why is the value of "C" changing in the following code? -
the output i'm getting given code "0" though initialized value of c "1"...can explain it... why value of "c" changing in following code??
#include <iostream> using namespace std; int c=1; // global initialized 'c' 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 value of 'c' return 0; }
because value of c being changed in below code :
else{ c=c+1; f(n-2); }
Comments
Post a Comment