How to return static variable from a function in C

1 Answer

0 votes
#include <stdio.h>

int returnStatic(void);

int main(int argc, char **argv) 
{ 
    printf("%d\n", returnStatic());
    
    return(0);
}

int returnStatic(void)
{
   static int n = 0;
   
   return ++n;
}

/*
run:

1

*/

 



answered Jun 4, 2015 by avibootz

Related questions

1 answer 246 views
2 answers 181 views
1 answer 163 views
163 views asked Dec 27, 2020 by avibootz
1 answer 154 views
154 views asked Jun 20, 2017 by avibootz
1 answer 110 views
1 answer 196 views
1 answer 188 views
...