I can declare a structure:
typedef struct
{
int var1;
int var2;
int var3;
} test_t;
Then create an array of those structs structure with default values:
test_t theTest[2] =
{
{1,2,3},
{4,5,6}
};
But after I’ve created the array, is there any way to change the values in the same way I did above, using only one line, specifying every value explicitly without a loop?
In C99 you can assign each structure in a single line. I don’t think that you can assign the array of structs in one line though.
C99 introduces compound literals. See the Dr. Dobbs article here: The New C: Compound Literals
You could assign to a pointer like this:
You could use memcpy as well:
Above tested with gcc -std=c99 (version 4.2.4) on linux.
You should read the Dr. Dobbs article to understand how compound literals work.