快速引用

  1. define

  2. 定义常量:#define M 25

  3. 定义表达式:#define M(a, b) ((a)>(b)?(a):(b))
    示例程序:
    #include <stdio.h>

#define MAX(a, b) ((a)>(b)?(a):(b))

      

void main(){

int c = MAX(5 + 8, 8);

printf("c = %d", c);

}

  1. 存储类型:

  2. auto(默认):未赋初值,不确定

  3. register

  4. static:局部static变量具有全局寿命和局部可见性,具有可继承性.未赋初值,自动赋初值为0或空字符.如果是外部static,表示只对当前文件有效.
    示例程序:

#include <stdio.h>

 

void test(){

static int a;

a++;

printf("a = %d\n", a);

}

 

void main(){

int i=0;

for( i = 0;i < 10; i++){

      test();

}

}

  1. extern:不是定义变量,而是扩展了外部变量作用域
    示例程序:

a.c
int a = 100;
test.c
#include <stdio.h>

void main(){

extern int a;

printf("a = %d\n", a);

}

typedef定义别名:

格式:typedef 原有数据类型 自定义数据类型
示例: typedef  INT  int a;
原文地址:https://www.cnblogs.com/itfenqing/p/4429458.html