Monday, May 24, 2010

How to let the compiler know if the variable is static.in c?

declare it as static,


// static1.cpp


// compile with: /EHsc


#include %26lt;iostream%26gt;





using namespace std;


void showstat( int curr ) {


static int nStatic; // Value of nStatic is retained


// between each function call


nStatic += curr;


cout %26lt;%26lt; "nStatic is " %26lt;%26lt; nStatic %26lt;%26lt; endl;


}





int main() {


for ( int i = 0; i %26lt; 5; i++ )


showstat( i );


}

dogwood

No comments:

Post a Comment