天天看点

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

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

#include <stdio.h>

typedef struct _led
{
	int ver;
	char name[10];
}LED;

int main(void)
{
	int i;

	LED leds[]={
			{
			.ver=3,
			.name="led3",
			},

			{
			.ver=4,
			.name="led4",
			},

			};
	for(i = 0; i < 2; i++)
	{
		printf("%d----%s\n",leds[i].ver,leds[i].name);
	}	
	return 0;
}           

将文件保存为 test.c

然后运行:

[email protected]:~/newmsg/test_struct$ gcc test.c  -o test

[email protected]:~/newmsg/test_struct$ ./test 

3----led3

4----led4

[email protected]:~/newmsg/test_struct$ 

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