what does static int mean in this situtation:
int x =42;
void g(int y)
{
static int x=7;
x+=y;
}
there is another function too and the main function. thanks
Printable View
what does static int mean in this situtation:
int x =42;
void g(int y)
{
static int x=7;
x+=y;
}
there is another function too and the main function. thanks
It means that the function g() has an int x that is persistent between calls, and in that particular situation, it will only be initialized to 7 once (the first time g() is called), and subsequently it will have whatever value was left in it from the previous call. It's sort of a like a global variable, except it is not 'seen' except inside that particular function.