自动变量和静态变量

//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
/*自动变量是在定义时被创建,在被定义他们的函数返回时系统会自动回收该空间
	块语句的局部变量和函数的形式参数都是自动变量
	如果只是让程序跑起来,auto可以省略。auto可以让程序更易读

*/
void autoRun(){  
	auto int x=0;  // 自动变量
	//自动变量,函数被调用时就存在,调用结束时就释放
	//地址未变,但值却每调用一次就不一样
	printf("%x\n",&x);

}

void staticRun(){
	static int x=0; //静态变量
	//静态变量,每次调用,值和地址都没有变化
	printf("%x\n", &x);
}
void main(){
	staticRun();

	printf("\n");

	staticRun();

	system("pause");
}

 

posted @ 2019-07-21 22:12  Coding_Changes_LIfe  阅读(438)  评论(0编辑  收藏  举报