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 242 views
2 answers 175 views
1 answer 159 views
159 views asked Dec 27, 2020 by avibootz
1 answer 151 views
151 views asked Jun 20, 2017 by avibootz
1 answer 105 views
1 answer 193 views
1 answer 177 views
...