use*_*512 4 c typedef structure
int main()
{
int a;
typedef struct
{
int i;
int j;
}type1;
typedef type1 type[10]; //Please explain this line ?
typedef struct
{
int l;
type c;
}type2;
type2 x;
x.c[0].i=1; //How can we write this??
x.c[0].j=2;
x.c[2].j=3;
printf("%d",x.c[2].j);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
程序正在成功编译,我正在考虑不要因为
typedef type1 type[10];
Run Code Online (Sandbox Code Playgroud)
请解释这里打字的行为.我所知道的是我们可以在typedef的帮助下定义一个别名.
输出:3
unw*_*ind 14
读取方式typedef是作为常规变量声明,变量的类型是给定别名的类型,变量名称是新别名的名称.
所以,在
typedef type1 type[10];
Run Code Online (Sandbox Code Playgroud)
如果我们放弃typedef我们得到:
type1 type[10];
Run Code Online (Sandbox Code Playgroud)
这明确定义type为10的数组type1.因此,typedef然后引入type"10的数组type1" 类型的名称.
| 归档时间: |
|
| 查看次数: |
155 次 |
| 最近记录: |