用typedef来定义数组

时间:2025-02-23 11:01:52
#include<> #include<> #include<iostream> /* 201732520:26:43 测试typedef和数组的用法 现在已经知道了,typedef能用来起别名,比如,typedef int ABC;那么,就好像int 的别名就是ABC. 在main中需要使用int 的地方,全部都可以用ABC来代替。比如,ABC num;其实就是int num;这个是typedef最基本的用法。 现在测试一下typedef有关数组的高级用法: 如果写了这句话 typedef int ARC[10]; 那么,在使用main中使用的话,直接使用ARC abc;其作用就是声明一个abc变量,这个变量内含有10int类型的数据。 */ typedef int ARC[10]; int main(void) { ARC abc;//由于使用了typedef,现在abc相当于内含10int类型的数组的数组名。 for(int index=0;index<10;index++) { abc[index]=index; } for(int index=0;index<10;index++) { printf("%d\n",abc[index]); } system("pause"); return 0; }

相关文章