a) For primitive data types, such as int, float, it cannot be recognized if it is initialized or not.
b) For pointers you can check if its nullptr or not
if(ptr != nullptr) { }
c) For a custom class, you need to introduce a bool element that can be set to true in the constructor so that we can use it to check if the object is initialized or not.
if(obj.isInitialized()) { }
source share