# clear int m?

This is a discussion on clear int m? within the C++ Programming forums, part of the General Programming Boards category; my program is looping because int m = (any integer) stops it from pausing because a condition is being satisfied. ...

1. ## 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)

2. 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`

3. 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.

4. 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 )

5. 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;```

6. 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.

7. So does that mean that when I create

int m;

its value is 0 anyway?

8. 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.

9. 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.

10. yep, brewbuck is right, int m; gives an unpredictable number. E.G it may contain
10 by default and 49 on another computer.

Popular pages Recent additions