Declare it like this in your function:
That means the first time your function is called, x starts with a value of 42. Whatever you change it to, that new value will be remembered, and next time you start the function, it will start
with the new value. It wont be 42 every time.
The technical way to describe such a variable is one having
static duration, and
local scope. Think of it like a hybrid local/global. It exists throughout the entire duration of the program (static duration). It's stored with any global variables, and follows the same rules of initialization, i.e. if uninitialized, it's zero, if initialized, it's initialized once at program start up, not every time the function starts. The difference between a static local and a global is that only the function with the static local declaration can see the variable (local scope).
Note that this means there is only one copy of the variable for the entire program. That means this solution can cause problems if you're using recursive functions (functions that call themselves, or that call other functions that then call it), but can also help in recursive functions, depending on what you want to do with it. It can also be a problem with multi-threaded apps (probably not an issue for you).