How to store variable value in a function in C++? asked Aug 17, 2020 in C++ by Pantycle_Genefanty (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 cpp variable function value Please log in or register to add a comment. 1 Answer 0 like 0 dislike answered Aug 17, 2020 by Pantycle_Genefanty (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 add a comment.