结构体数组的初始化

结构体数组的初始化

在c中,原来还能这么用,又孤陋寡闻了一把。

   struct key {
       char *word;
       int count;
   } keytab[] = {
       "auto", 0,
       "break", 0,
       "case", 0,
       "char", 0,
       "const", 0,
       "continue", 0,
       "default", 0,
       /* … */
       "unsigned", 0,
       "void", 0,
       "volatile", 0,
       "while", 0
   };

当然,上面的用法在结构体中数据成员不多的情况能够做到清晰明了,否则,就换成这么用:

   { "auto", 0 },
   { "break", 0 },
   { "case", 0 },
   ...

Leave a Reply

Your email address will not be published. Required fields are marked *