C structure initialization problem, c structure Initialization
Array initialization in struct my code
C/C ++ code # include <stdio. h> # include <stdlib. h> struct a {int length; int c [5];} B; int main () {B. c = {1, 2, 3, 4, 5 };}
The compiler reports an error during debugging.
------ Solution ------------------ your struct is a global variable and has been allocated space before entering main.
{} Can only be used for initialization and can only be used for definition. {} Is not allowed to assign values to arrays.
Your code should be changed like this.
C/C ++ code # include <stdio. h> # include <stdlib. h> struct a {int length; int c [5];} B = {0, 1, 2, 3, 4, 5}; // 0 is initialized to length, the last five are for the array, in order. Int main () {}------ solution -------------------- C/C ++ code # include <stdio. h> # include <stdlib. h> struct a {int length; int c [5];} B; int main () {int I; for (I = 0; I <5; I ++) b. c [I] = I + 1 ;}
------ Solution -------------------- refer to the initialization of a common array such as {1, 2, 3, 4, 5 }.
The allocated space can only be assigned values individually or cyclically.
The initialization of the number of character groups is the same as above ..