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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -