C Exercise Examples 41 - static
100 cases of classic C language
Title: Learning the definition of static variable usage of static.
Program Analysis: None.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #include<stdio.h> int main() { void fun(); for(int i=0;i<3;i++) fun(); return 0; } void fun() { int i=0; static int static_i=0; printf("i=%d\n",i); printf("static_i=%d\n",static_i); i++; static_i++; }
The above example output is:
i=0 static_i=0 i=0 static_i=1 i=0 static_i=2