C语言中static的用法

static

static变量

C语言中static的用法static变量只能初始化一次

在函数内部定义的static变量,

在函数调用过程中,能够保存值,意思就是下次调用函数,这个函数里的这个变量有值,不能被再次初始化

#include<stdio.h>
void a()
{
    static int n = 5;
    printf("%d\n",n);
    n++;
}

void main()
{
    int i;
    for(i=0; i<5; i++)
        a();
}

输出结果如下:

static函数

 

extern

 

const

 

posted @ 2013-05-19 23:54  独墅一枝花  阅读(594)  评论(0编辑  收藏  举报