欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C语言--键值对赋值

程序员文章站 2022-06-12 20:21:41
...
#include<stdio.h>

typedef struct {
	char name[10];
	int id;
}STD;



int main(int argv,char *argc[])
{
	STD test = {
	 .name = "gong",
	 .id = 10
	};
	STD test1[3] = {
	  [0] = {.name = "gogn1",.id = 11,},
	  [1] = {
	    .name = "yu1",
		.id = 12,
	  }
	};
	int test2[3] = {[0] = 0,[1] = 1,[2] = 2};	
	printf("%s,%d\n",test.name,test.id);
	printf("%s,%d\n",test1[0].name,test1[0].id);
	printf("%s,%d\n",test1[1].name,test1[1].id);
	printf("%d,%d,%d\n",test2[0],test2[1],test2[2]);

    return 0;
}

 

相关标签: C语言 c语言