Directly on the example .
#include <stdio.h>struct student_st{char c;int score;const char *name;}; static void Show_student (struct student_st *stu) {printf ("c =%c, score =%d, name =%s\n", Stu->c, Stu->score, stu-& Gt;name);} int main (void) {///Method 1: Initializes the struct student_st in the order of member declarations S1 = {' A ', "Alan"};show_student (&S1);//Method 2: Specifies initialization, The member order can be variable, the Linux kernel uses this way to struct student_st s2 = {. Name = "Yunyun",. C = ' B ',. Score = 92,};show_student (&S2);//Method 3: Specify initialization, member order can be indefinite struct student_st s3 = {c: ' C ', Score:93,name: "Wood",};show_student (&S3); return 0;}
Operation result :
If you want to initialize a struct array , you can use the {{}, {}, {}} methods, such as
struct Student_st stus[2] = {{. c = ' d ',. Score = 94,/* can also initialize only part of the member */},{.c = ' d ',. score = 94,.name = "Xxx"},};
Three ways to initialize C language structure