C语言面试题:有没有一个函数在主函数执行前就执行,在主函数退出后再执行?

程序分析:

第一串代码实则是一个自定义的头文件(命名为: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(类型限定符)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值