guys i was wondering about local variable
my question is something like this
I always and i mean almost always initialize my variable to be a global variable, but i was wondering could i initiate it in someway so it to become a local variable
heres an example:
int Count=0;
void setup()
{ yada yada yada}
void loop()
{
did something heres that causes
Count++;
}
but could somehow i want it to be like this
void loop()
{
int Count=0;
somthing happen somwhere here
and then Count++;
}
i know that if i do it as the second way that is initializing the Count in the loop section will make the Count value reset to 0 every time it loop
Sorry AWOL if i'm not clear with my question, I want to know if i could initialize Count variable as a local variable inside the void loop()?
i what the value to be the last value that it has b4 the loop function loop around, i dont want it to be reset back to 0.
ash901226:
now i know what static does, so this way i do not need to declare to may global variable now huh.
No you don't. There are lots of different static so keep an open mind for next time it may mean something else.
If you want a variable only that function needs to access, you can use static. Non static local variables are released after function call so memory is free for other things. Static variables are kept so don't define too many of them.