4
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;
}

程序正在成功编译,我不希望因为

    typedef type1 type[10];

请在这里解释 typeded 的行为。我所知道的是我们可以在 typedef 的帮助下定义一个别名。

输出:3

4

1 回答 1

14

读取的方式typedef是作为常规变量声明,变量的类型是被赋予别名的类型,变量名是新别名的名称。

所以,在

typedef type1 type[10];

如果我们放弃typedef我们得到:

type1 type[10];

这清楚地定义type为 10 的数组type1。因此,typedef接下来介绍type类型“array of 10 type1”的名称。

于 2013-01-29T11:57:53.347 回答