How can one assign values to a 2D array on stack memory. I tried the following, which doesn’t seem to work. Of course one can assign each value at a time, but I was interested in assigning the values in one go. Any ideas?
double phi[2][5];
phi[0] = {1, 0, 2, 1, 0};
phi[1] = {1, 0, 2, 1, 0};
You can initialise the array:
Note omitted elements will default to zero so the following would produce the same result:
If the compiler supports C99 then compound literals could be an option but the type of
phiwould need to change to a pointer to an array ofdouble[5]. For example:But all dimensions must be assigned, not individual dimensions (see demo http://ideone.com/NxdUO ).