1

Will the static variable declared in a recursive function be destroyed once the first return executes?
For example:

int func(int x) {
    static int n;
    // recursive call
}
chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 1
    Static variables are destroyed on program exit. They are initialized when the code is first encountered. – jspcal May 30 '18 at 18:32
  • 1
    Just so that the duplicate makes more sense - the fact that function is recursive have no effect on lifetime of a static variable. – SergeyA May 30 '18 at 18:39

0 Answers0