How do you reset a int ?

Hi
I want to reset a int to nothing ? how do I do this ?

something like this !, but this does not work because I´m not allowed to use null;
int x;

void draw(){
int x = 5;
int x = null;
}

int x;  // Creates a global variable called x containing 0

void draw(){
int x = 5;  // Creates a local variable called x containing 5
x = 0;       //  Changes the local variable x to contain 0
}  // End of function.  Local variable stops existing
void draw(){

Makes it look like Processing code not Arduino code.

something like this !, but this does not work because I´m not allowed to use null;
int x;

void draw(){
int x = 5;
int x = null;
}

This would give you 3 variables with the same name. Why would you want to do that?

I want to reset a int to nothing ?

Why? No int ever is set to nothing. What are you trying to accomplish?

An int can't be "nothing", it's always a number of some kind.

Depending on it's valid range in the program it's common to set it to -1 to indicate that it's not valid, an error or whatever.

If all values are valid in your code then you need a separate flag to indicate that the int is not currently containing valid data.

As PaulS said, what do you really want to do?


Rob

You can create an object wrapping an int, or you can use a pointer to an int.
Or -simpler- have an additional boolean saying undefined/defined.

Usually, the "special value" method indicating it's undefined, is easiest.
It just depends on the use case, but usually, there are some invalid states, even in a small signed 16 bit integer.
Take -32768 = 0x8000, if 0 and -1 are both "not null".

use it like this:

#define INVALID 0x8000
...
int x = INVALID;
...
if (x == INVALID)
x = initializeIt();