Struct array initialization, struct Array
Const int MAXN = 100; struct A {int a, B ;}; struct A arr [100]; // at this time, it is compiled through struct A arr [MAXN]; // The compilation fails at this time. Why?
Struct array Initialization
/*
# Include <stdio. h>
# Include <stdlib. h>
Struct record {
Char URL [40];
Char Title [20];
Char Keyword [16];
Double PageRank;
};
Typedef struct record Record;
Int main ()
{
Record t [2] = {"ii", "jj", "kk", 0 },{ "ii", "jj", "kk", 0 }};
Printf ("% s", t [1]. URL );
Return 0;
}*/
If you want to initialize it when defining it, it must be the same as the above. Otherwise, you must initialize it one by one, as shown in the following code.
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
Struct record {
Char URL [40];
Char Title [20];
Char Keyword [16];
Double PageRank;
};
Typedef struct record Record;
Int main ()
{
Record t [2];
Strcpy (t [0]. URL, "ii ");
Strcpy (t [0]. Title, "jj ");
Strcpy (t [0]. Keyword, "kk ");
T [0]. PageRank = 0.0;
Strcpy (t [1]. URL, "ii ");
Strcpy (t [1]. Title, "jj ");
Strcpy (t [1]. Keyword, "kk ");
T [1]. PageRank = 0.0;
Printf ("% s", t [1]. URL );
Return 0;
}
C language, how to initialize struct Arrays
Method 1:
Struct student stu [100] = {0 };
Method 2:
Struct student stu [100];
Memset (stu, 0, sizeof (stu ));