C/C++: Can I access static variables inside a function from outside? For example:
#include
using namespace std;
void f()
{
static int c
No, you can't, neither in C nor in C++.
If you want to maintain state associated with a function, define a class with the appropriate state and a member function. (In C++. You've also tagged the question with C; the same technique works but you need to do all the groundwork yourself.)
Although they have their uses, most of the time non-const static locals are a bad idea. They make your function thread-unsafe, and they often make it "call-once".