C语言中结构体成员变量加“点”问题


笔者最近学习ARM9,各种问题不会,在努力探索中,不知道怎么把以前ARM7的知识和现在的联系起来,但是最近发现一个C语言的疑惑,属C语言基础问题,望大神们指点指点。

  1. #include <stdio.h>  
  2.   
  3. typedef struct _led  
  4. {  
  5.     int ver;  
  6.     char name[10];  
  7. }LED;  
  8.   
  9. int main(void)  
  10. {  
  11.     int i;  
  12.   
  13.     LED leds[]={  
  14.             {  
  15.             .ver=3,  
  16.             .name="led3",  
  17.             },  
  18.   
  19.             {  
  20.             .ver=4,  
  21.             .name="led4",  
  22.             },  
  23.   
  24.             };  
  25.     for(i = 0; i < 2; i++)  
  26.     {  
  27.         printf("%d----%s\n",leds[i].ver,leds[i].name);  
  28.     }     
  29.     return 0;  
  30. }  

将文件保存为 test.c

然后运行:

et@Ubuntu:~/newmsg/test_struct$ gcc test.c  -o test
et@ubuntu:~/newmsg/test_struct$ ./test
3----led3
4----led4
et@ubuntu:~/newmsg/test_struct$

为什么struct可以这样对成员变量尽兴初始化,求大神们指点指点

相关内容