一,auto,static和extern 的使用方法
extern 是声明外部变量的
/*************************************************************************
> File Name:
> Author: songli
> QQ:2734030745
> Mail: 15850774503@163.com
> Created Time:
************************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ch = 5;
extern int i; //在外部文件中找
int main(int argc, char *argv[])
{
extern int ch; //在文件内部找
printf("\n");
system("pause");
return EXIT_SUCCESS;
}
2,全局变量和局部变量的区别
在声明的的地址比较
/*************************************************************************
> File Name:
> Author: songli
> QQ:2734030745
> Mail: 15850774503@163.com
> Created Time:
************************************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int x = 30;
printf("x = %d, x : %p \n", x, &x);
{
int x = 100;
printf("x = %d, x : %p \n", x, &x);
}
printf("x = %d, x : %p \n", x, &x);
while (x++ < 33) //外部变量
{
int x = 100;
x++; //这个是内部变量
printf("x = %d, x : %p \n", x, &x);
}
printf("x = %d, x : %p \n", x, &x);
printf("\n");
system("pause");
return EXIT_SUCCESS;
}