While studying static qualifier in C, I wrote the following code by mistake.
I thought that getEven() function would not be compiled but it works well.
why can i declare a variable without type?
I tried some test and found that the type of static variable without type is 4 byte integer.
//This code works well.
int getEven(int i) {
static int counter = 0;
if (i%2==0) {
counter++;
}
return counter;
}
//I thought this code would make compile error, but it also works well.
int getEven_(int i) {
static counter = 0; //No type!
if (i % 2 == 0) {
counter++;
}
return counter;
}