See also this and this
You can write:
struct abc
{
int foo;
double matrix[2][2];
};
void f()
{
abc test =
{
0, // int foo;
{0,0,0,0} // double matrix[2][2];
};
}
I've added foo
for clarity on why the additional set of {}
around the array.
Note that this kind of structure initialisation can only be used with an aggregate data type
, which roughly means a C-link struct.
If you really need to construct and then assign, you may need to do something like:
struct Matrix
{
double matrix[2][2];
};
struct abc2
{
int foo;
Matrix m;
};
void g()
{
abc2 test;
Matrix init = { 5,6,7,8};
test.m = init;
}