How to check if a variable has been initialized in C?

Is there a way to check if a variable has been initialized or not in C?

How to check if a variable has been initialized in C?

If you want o check if a variable is set i.e it has been assigned some value by using C programming there is no official way provided by C. But you can find a work around for this.

First solution is to use a sentinel form. If you know that a variable (say) X will never have a value -1 then you can initially set it to the same value. Later, you can check if it contains -1 or not, if it does not not contain -1, X is not initialized; otherwise initialized.

Second solution is to use another variable as flag. Initially set flag to false (0). If the variable gets initialized set this variable to true (1). Later you can check whether this variable is true or false and decide accordingly whether the desired variable is initialized or not.