auto存储类
{
int mount;
auto int mount
}
这两个变量都在auto存储类中,局部变量默认就在auto存储类中
register存储类
{
register int mount;
}
register修饰的变量代表这个变量可能存储在寄存器中,具体存储在哪取决于硬件和实现的限制,但是可能存储在寄存器中,那么他的大小也就最大只能是寄存器的大小,还不能用&运算符,因为他没有内存位置
static存储类
static如果全局变量的话,代表这个全局变量可以被任何函数调用(和Java一样),如果修饰局部变量的话,代表这个局部变量不会每次进入这个方法的时候都去初始化。
#include <stdio.h>
/* 函数声明 */
void func1(void);
static int count=10; /* 全局变量 - static 是默认的 */
int main()
{
while (count--) {
func1();
}
return 0;
}
void func1(void)
{
/* 'thingy' 是 'func1' 的局部变量 - 只初始化一次
* 每次调用函数 'func1' 'thingy' 值不会被重置。
*/
static int thingy=5;
thingy++;
printf(" thingy 为 %d , count 为 %d\n", thingy, count);
}
输出
thingy 为 6 , count 为 9
thingy 为 7 , count 为 8
thingy 为 8 , count 为 7
thingy 为 9 , count 为 6
thingy 为 10 , count 为 5
thingy 为 11 , count 为 4
thingy 为 12 , count 为 3
thingy 为 13 , count 为 2
thingy 为 14 , count 为 1
thingy 为 15 , count 为 0
extern存储类
调用另一个文件的函数或者全局变量的时候用extern来声明