How do I ask an if statement if a variable has no value?

I'm fairly new to programming, so I really only know basics. But I'm trying to make an if statement that basically says:

If this variable doesn't have a value
then assign it a value


Can anyone tell me how to do this?
A variable always has a value.
At most, you can define some state (like 0 or -1 for an integer) that you define as "no value".
Wait, but i thought if you declare a variable like

int i;

it wont have a value until you initialize it
That is incorrect. It will have a value. It takes up some memory and that memory has some numbers in it. Those numbers could be anything at all. Those numbers are the value.
It gives me a warning saying that an uninitialized variable 'i' is being used...
As it should. i does have a value, it's just unspecified which one (it can be some random value).
Just try printing it.
Uninitialized means you have not set a value.

int i; // No value set

See? No value has been set. It could be anything.

i = 7;

Now a value has been set. The value 7.
Hmm... ok, thanks for the help :D
Topic archived. No new replies allowed.