is there a way to reset a boolean variable?

originally i have a boolean variable set to false, and if it met a certain condition, the boolean variable would set to true.
so, is there something i can use to essentially reset the boolean variable back to false without actually having to manually set that variable back to false or making a second boolean variable?

note: i'm pretty new to c++ and i'd appreciate it if you guys gave me a really simplified answer (if there really is a way to reset the boolean variable)
Last edited on
Hi,
Use this :
ok = !ok;
Does that help? :)
oh okay lol that makes sense i don't know why i didn't think of that before, i'll try that out now
okay another question, is it possible to erase or delete a value that's in a variable?
like let's say that int num=3. is there a way where i can delete the value from it and just have it as if i never assigned it anything in the first place?
You always want to assign a value to an int variable, even if you're not using it now. While setting up a variable and you don't want it to have a value yet, just set it up as: int num = 0. And f you no longer want it to be 3 just change it back: num = 0.
closed account (48T7M4Gy)
Unless the variable is defined as a constant you can re-assign the variable to any compatible value you like. But there is no need to if you don't intend to use it again.

You re-assign the initialised int num = 3; by the statement num = 5;
Last edited on
Note that this line of code ok = !ok; sets the variable to the opposite value.

If ok is true it sets it to false.
If ok is false it sets it to true.

That means it will not actually reset the variable to the value that it was originally initialized to, unless it happens to have the opposite of that value.
Last edited on
Topic archived. No new replies allowed.