# clear int m?

• 03-12-2010
mikeyp
clear int m?
my program is looping because
int m = (any integer)
stops it from pausing because a condition is being satisfied.

How do I clear m so that
m = (nothing)
• 03-12-2010
GReaper
Quote:

Originally Posted by mikeyp
How do I clear m so that
m = (nothing)

????

A variable always contains something!!! It's not a pointer!
But you could set it to 0 in order to be casted to false when checked:

Code:

`if (!m) {/*...*/} // true when m = 0, false otherwise`
• 03-12-2010
iMalc
So you have a value that consists of 32 bits (I'm going to assume 32 bits anyway) which are either one or zero and you want it to equal "nothing"?
Well you'll just have to invent some combination of 32 ones and zeros that you'd like to mean "nothing" and assign that. Well you could set all 32 bits to zero I guess, in other words assign the value zero to m.

Perhaps you can just assign a value that stops the condition from being satisfied.
• 03-12-2010
GReaper
Actually, zero is (nothing), so it's safe and meaningful to set m to zero and do what i told you ( some times i guess :) )
• 03-12-2010
MK27
You could also use an int pointer, and than can be set to NULL, which is not the same as having the pointer contain 0.
Code:

```int n = 0, *x = &n; x = NULL;```
• 03-12-2010
_Mike
Quote:

Originally Posted by Sipher
Actually, zero is (nothing), so it's safe and meaningful to set m to zero and do what i told you ( some times i guess :) )

0 is not nothing, it's an integer value just like 1 and 12345 are. There is no possible way to have an int containing nothing.
It is often used to represent nothing, but that's not the same thing as being nothing.
• 03-12-2010
mikeyp
So does that mean that when I create

int m;

its value is 0 anyway?
• 03-12-2010
brewbuck
Quote:

Originally Posted by mikeyp
So does that mean that when I create

int m;

its value is 0 anyway?

No. Its value is undefined. That doesn't mean it has no value, but it means the value is unpredictable.
• 03-13-2010
cpjust
You could also create a class that represents an int, but also lets you set the state of the class to 'nothing'. Personally, I think that's overkill. Just use 0, or a NULL pointer.
• 03-13-2010
UltraKing227
yep, brewbuck is right, int m; gives an unpredictable number. E.G it may contain
10 by default and 49 on another computer.