您现在的位置是:课程教程文章

c语言中static的使用

2023-12-13 23:04课程教程文章 人已围观

1、若局部变量用static修饰,则该变量为局部静态变量。

#include<stdio.h>

intmain()
{
staticintx=0;//局部静态变量
printf("www.codersrc.com");
return0;
}

2、若全局变量用static修饰,则该变量为全局静态变量。

#include<stdio.h>

staticintx=0;//全局静态变量

intmain()
{
printf("www.codersrc.com");
return0;
}

3、如果用static修饰函数,则该函数为静态函数。

#include<stdio.h>


staticintfunc()//静态函数
{
printf("静态函数");
return0;
}

intmain()
{
func();
printf("www.codersrc.com");
return0;
}
/*
输出:静态函数www.codersrc.com
*/

以上就是c语言中static的使用,希望对大家有所帮助。更多C语言学习指路:C语言教程

本教程操作环境:windows7系统、C11版,DELL G3电脑。

课程教程:c语言中static的使用

上一篇:c语言中static修饰局部静态变量

下一篇:没有了

站点信息

  • 文章统计篇文章