How to store variable value in a function in C++? asked Aug 17, 2020 in C++ by Pantycle_Genefanty (14.9k points) 0 like 0 dislike 62 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 Your comment on this question: Your name to display (optional): Email me at this address if a comment is added after mine:Email me if a comment is added after mine 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. 1 Answer 0 like 0 dislike answered Aug 17, 2020 by Pantycle_Genefanty (14.9k 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 comment on this answer: Your name to display (optional): Email me at this address if a comment is added after mine:Email me if a comment is added after mine 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.