Need help: Explanation of a static storage class
I am going through a tutorial on C and just ran into static storage class on an int. Reading this code I would assume that the variable number is set to 7, print statement says number is 7. Than 7 turns to 8, we return to the top of the loop, "number is than set to 7 again", than we print number is 7. Can someone help me understand how 7 gets incremented and than holds that value even though when it loops through again number is defined again and set to 7.
Code:
int main( int argc, char ** argv )
Code:
{
for (int i =1; i <= 5; ++i) {
static int number = 7;
printf("number is %d\n" , number++);
}
return 0;
}
Output:
number is 7
number is 8
number is 9
number is 10
number is 11