Your question has nothing to do with dynamic allocation.
You are asking about how to determine if a variable has a "valid" value or not.
This is done differently depending on the situation.
For example, if you have an array of ints whose valid values are all positive you can initialize them to 0 (or -1 if 0 is a valid value) to indicate an invalid value.
If both positive and negative (and zero) values are valid you could use INT_MIN to indicate an invalid value.
If valid values must also include INT_MIN then you would need to do something like you are doing where a separate boolean (or possibly a bit-array to save space) indicates if the value is valid. This is pretty rare.
For different data types you could come up with similar schemes.