1.作用: “建议”编译器把变量放到寄存器内,编译器不一定听你的(傲娇)!!
2.速度:寄存器>高速缓存>内存,寄存器空间很宝贵(非常非常少)
3.寄存器不支持取地址, 不支持静态

过度使用register可能会造成寄存器不足,反而降低程序效率,而且有些东西就算你不建议他也会自己做,不要小看现代编译器几个GB的代码仓库(哭,拉取过…)

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <time.h>

void Test()
{
	register int a = 0;
	for (int i = 0; i < 2000000000; i++)
	{
		a++;
	}
}
void Test2()
{
	int a = 0;
	for (int i = 0; i < 2000000000; i++)
	{
		a++;
	}
}
int main()
{
	clock_t start, stop;
	double duration;

	// 不在测试范围内的准备工作写在clock()调用之前 
	start = clock();//开始计时 

	Test();

	stop = clock();//停止时间 
	duration = ((double)(stop - start)) / CLK_TCK;
	// 其他不在测试范围的处理写在后面,例如输出duration的值 

	printf("%f\n", duration);

	start = clock();//开始计时 
![请添加图片描述](https://img-blog.csdnimg.cn/65a706c2d9814d1eb3fcb0626995eca1.png)

	Test2();

	stop = clock();//停止时间 
	duration = ((double)(stop - start)) / CLK_TCK;
	printf("%f\n", duration);

}

请添加图片描述