static修饰得局部变量
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void test()
{
static int a = 1;
a++;
printf("a = %d", a);
int b = 2;
b++;
printf("b = %d\n", b);
}
int main()
{
int i = 1;
while(i<5)
{
test()
i++;
}
return 0;
}
static修饰的局部变量出大括号后不会被销毁,而是被保存在内部,下次调用时值不变
全局变量可以跨文件使用 只需要用extern 声明即可引用
extern修饰全局变量的时候改变全局变量的作用域,使全局无法跨文件引用。
extern int 全局变量
函数也可以跨文件使用(定义的函数被 static修饰 就无法跨文件使用,static将外部链接属性消除)
define定义常量和宏
#define abc 100//定义常数
指针
指针变量就是用来存放地址的
数据类型为 【变量类型*】
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
char ch = “abb”;
char* p0 = &ch;
int a = 10;
int* p = &a;
*p = 20;//*--为解引用操作符 *p的意思为地址p所代表的变量
printf("a = %d", a);
printf("a = %d", *p);
return 0;
}
结构体
用于描述复杂对象——结构体
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct book
{
char name[20];//必须规定数组大小
int price;
};
int main()
{
struct book bb = { "人间失格", 45 };
struct book* pp = &bb;//struct book 是我们人为规定的数据类型
printf("%s\n%d\n", (*pp).name, pp->price);
//可用指针的形式表示 但是加()可用->代替“.”此时不加*和()
printf("%s\n%d\n", bb.name, bb.price);
bb.price = 30;//修改变量
printf("%s\n%d\n", bb.name, bb.price);
return 0;
}