Skip to content

Instantly share code, notes, and snippets.

@bopin2020
Created February 25, 2021 12:17
Show Gist options
  • Save bopin2020/03fd0ead6662f58ce01610a129fff932 to your computer and use it in GitHub Desktop.
Save bopin2020/03fd0ead6662f58ce01610a129fff932 to your computer and use it in GitHub Desktop.
/*
C
const
static
static const 区别
*/
const 表示常量,存储在静态存储区。
static 修饰变量 仅作用在当前文件内
// main.c
#include "test.h"
int p = 10; // 外部链接
static int p2 = 100; // 内部链接
int main() {
EnablePriv();
const int num = 2; // 静态存储区的只读数据区
static char name[] = "name"; // 规定作用域 存储方式
// 1. 局部变量 static
return 0;
}
// Test.h 头文件
// 函数声明
BOOL EnablePriv();
// 其他.c文件
extern int p; // 可以通过extern 引用外部定义的非 static变量
extern int p2; // 编译失败
BOOL EnablePriv()
{
printf("%d\n",p);
// printf("%d\n",p2);
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment