in C++ by (16.3k points)
0 like 0 dislike
107 views

How I can value of a function variable be preserved between calls to that function in the C++ programming language?


c++ storing value of a variable in a function

1 Answer

0 like 0 dislike
by (16.3k points)

Use static modifier on this function variable when creating it:

void fnc() {
	static bool flg = true;
}

For details see static variable in function in C++.

Please log in or register to answer this question.