大家好,又见面了,我是你们的朋友全栈君。
#include <stdio.h> #include <stdint.h> #include <string.h> #include <math.h> #include <stdlib.h>
void staticFun(void) { static uint8_t data = 0; data++; data++; printf(“static function data = %d\r\n”,data); }
void NostaticFun(void) { uint8_t data = 0; data++; data++; printf(“no static function data = %d\r\n”,data); }
int main() { //static 功能 printf(“局部static的功能\r\n”); staticFun(); staticFun(); staticFun(); staticFun();
//没有statuc的功能 printf(“没有static的功能\r\n”); NostaticFun(); NostaticFun(); NostaticFun(); NostaticFun();
return 0; }
static函数局部变量保存这上一次的内容依次递增,而没有static的变量每次调用函数,都只是从0开始递增。
打印结果如下:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160339.html原文链接:https://javaforall.cn