static doesn't mean const.
From MSDN:
When modifying a variable, the static
keyword specifies that the variable
has static duration (it is allocated
when the program begins and
deallocated when the program ends) and
initializes it to 0 unless another
value is specified. When modifying a
variable or function at file scope,
the static keyword specifies that the
variable or function has internal
linkage (its name is not visible from
outside the file in which it is
declared).
A variable declared static in a
function retains its state between
calls to that function.
When modifying a data member in a
class declaration, the static keyword
specifies that one copy of the member
is shared by all instances of the
class. When modifying a member
function in a class declaration, the
static keyword specifies that the
function accesses only static members.
The value of static is retained between each function call, so for example (from MSDN again):
// static1.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
void showstat( int curr ) {
static int nStatic; // Value of nStatic is retained
// between each function call
nStatic += curr;
cout << "nStatic is " << nStatic << endl;
}
int main() {
for ( int i = 0; i < 5; i++ )
showstat( i );
}
In your example, x will increment as expected because the value is retained.