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 236 views
2 answers 170 views
1 answer 153 views
153 views asked Dec 27, 2020 by avibootz
1 answer 145 views
145 views asked Jun 20, 2017 by avibootz
1 answer 102 views
1 answer 185 views
1 answer 171 views
...