--- In c-prog@yahoogroups.com, "gIe - papilon" <[EMAIL PROTECTED]> wrote: > > simple classic problem.. > > i get stuck when try to insert static integer function to count how > much step that my program do in a hanoi program,, i made it on C... >
The 'static' keyword ensures a variable retains it's value until changed or the program ends. example below: This function will always return 1 because every time the function is called, memory is set aside for the variable 'a' and then it is set to 0. 'a' is dynamic. int count(void) { unsigned int a = 0; a++; return a; } This function will return how many times the function was called until the variable 'a' overflows back to 0. The 'static' keyword makes sure memory is allocated for 'a' when the program begins and deallocated when the program ends. int count(void) { static unsigned int a = 0; a++; return a; } Cheers... Mark