Quote:
|
Originally Posted by mightywombat
as an addition to my last post, what does the keyword static mean as well? as in:
static unsigned int divisor =0;
|
Static means that only one copy is used of the variable in all instances of the function. For example,
void foo(){
static int count = 0;
count++;
printf("%d", count);
}
int main(int argc, char *argv[]){
while(true)
foo();
}
would print out 123456789101112, etc whereas
void foo(){
int count = 0;
count++;
printf("%d", count);
}
would just print out 1 every time since the function can't keep track of things between calls.
As for volatile, it basically tells the compiler that it's possible that something other than the program itself could change the value of this variable, so don't try to do any crazy optimization stuff. Chances are that you won't really need it much (if ever), but it's good to know its there just in case.
-Rob