搜索文档
定义全局常量
语句位置
作为全局常量,其定义位置要与主函数统计,一般情况下定义在编译语句的下面。
关键字:
#define代码:
c#include <stdio.h> #include <stdlib.h> // 定义全局常量 #define LIST_INNIT_LENTH 100 #define LIST_CREMENT 20 // 主函数 int main() { int a = LIST_INNIT_LENTH + LIST_CREMENT; printf("全局常量的和为:%d\n",a); }运行效果

typedef 用法
说明:typedef 是为现有的类型起一个别名,使使用起来更加的方便,注意一点,它并没有产生新的类型。
代码:
c#include <stdio.h> #include <stdlib.h> // 定义全局常量 #define LIST_INNIT_LENTH 100 // 总长度 #define LIST_CREMENT 20 // 每次增加的长度 typedef int let; // 主函数 int main() { let a = LIST_INNIT_LENTH + LIST_CREMENT; printf("使用 typedef 语法给 int 类型起别名后运行结果为:%d\n",a); }运行效果

