1. How can I check if a variable has been initialized (if it exists).
2. How can I check if a variable is empty (if the variables contains data).
I'm using g++.
1. How can I check if a variable has been initialized (if it exists).
2. How can I check if a variable is empty (if the variables contains data).
I'm using g++.
Initializing the variable means giving it a value. Declaring a variable means to create (i.e. it exists)
As for your questions, look at the code. ;) If the variable hasn't been given a value, then it has not been initialized, it has only been declared.
You shouldn't have to, as long as you initialize you variable upon
deceleration.
You can always do this if you like :
const int NOT_INITIALIZED_VALUE = 0;
int i = NOT_INITIALIZED_VALUE ; //set to default value
int j = 4;
if(i == NOT_INITIALIZED_VALUE ) cout <<" i is not initialized\n";
if(j == NOT_INITIALIZED_VALUE ) cout <<" j is not initialized\n";
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.