I had a doubt about the static keyword.
[insert]
Code:
#include <stdio.h>
#include <stdlib.h>
static int count;
int road;
void func();
int main(void)
{
static int i = 3;
printf("\n %d", i);
printf("\n %d", count);
printf("\n %d", road);
i = 1;
count = 1;
road = 1;
for(i = 0 ; i< 5 ; i++){
func();
}
printf("\n %d", i);
printf("\n %d", count);
printf("\n %d", road);
return 0;
}
void func(){
static int i = 5;
i = 3;
printf("\n %d", i++);
}
i had a couple of questions regarding the usage of static keyword in c.
1. Once i initialize the variable declared as static, it can be assigned a new value again. I thought that once a static variable is declared as static it cannot be changed to a new value. But then i tried the above program and the value of the variable declared as static can be changed. Is this true?
2. Also in the code above main() i have declared two variables count, and road with road not having the static identifier. So is road a static variable or an auto variable.