in C++ by (12.3k points)
0 like 0 dislike

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 (12.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++.

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.