C语言-------结构体定义时赋值的三种方式

#include 

struct Time
{
	int hour;
	int min;
	int sec;
};
//必须按照结构体顺序
struct Time t1={
	17,
	49,
	54
};
//与结构体顺序无关
struct Time t2={
	.min=49,
	.sec=54,
	.hour=17
};
//与结构体顺序无关
struct Time t3={
	min:49,
	sec:54,
	hour:17
};


int main()
{
	printf("t1:%d:%d:%d\n", t1.hour, t1.min, t1.sec);
	printf("t2:%d:%d:%d\n", t2.hour, t2.min, t2.sec);
    printf("t3:%d:%d:%d\n", t3.hour, t3.min, t3.sec);
   return 0;
}
//结果输出
t1:17:49:54
t2:17:49:54
t3:17:49:54

你可能感兴趣的:(#,C语言,c语言,开发语言,后端)