程序分析:
第一串代码实则是一个自定义的头文件(命名为:tmp.h )(为了把系统的头文件与自定义的头文件做出区分,我们一般把自定的头文件用“ ” 来代替< >)
第二串代码是在第三串代码之外的一个 .cpp 文件,
第三串代码是主函数,在主函中运行中,使用 extern来寻找存在于其他文件当中的需要的函数或变量(如:My_Max(int,int) )
int ggg = 123;
int My_Max(int a, int b);
int arg1 = 10;
int g_b;
static int g_sc;//修改链接属性为内部
const int ca = 111;//const修饰的变量默认链接属性是内部的
//extern const int ca = 111;//但是如果还是想让别人能看到 则前面+extern,强行修改链接属性为外部
int My_Max(int a, int b)
{
return a > b ? a : b;
}
static int My_Min(int a, int b)
{
return a > b ? b : a;
}
#include <stdio.h>//直接去默认路径include里去找
#include "tmp.h"//1.去去默认路径找 2.如果1没有找到,再来项目中找
int main()
{
printf("主函数执行\n");
int a = 110;
printf("%d\n", a);
printf("主函数结束\n");
//extern const int ca;
//printf("%d\n", ca);
extern int My_Max(int, int);
//extern int My_Min(int, int);
//int tmp = My_Min(100, 200);
int tmp = My_Max(112, 22);
printf("%d\n", tmp);
printf("%d\n", ggg);
return 0;
}
运行结果如下:
面试题:static和const区别?
1. static(类型说明符)
2. const(类型限定符)