In C a programmer can declare an array like so:
unsigned char Fonts[2][8] {
[1] = {0, 31, 0, 31, 0, 31, 0, 31}
};
And element [0]
is likely random bits. Is there a similar way in C++?
In C a programmer can declare an array like so:
unsigned char Fonts[2][8] {
[1] = {0, 31, 0, 31, 0, 31, 0, 31}
};
And element [0]
is likely random bits. Is there a similar way in C++?
Why not just do
unsigned char Fonts[2][8] {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 31, 0, 31, 0, 31, 0, 31}
};
?
You can do this:
unsigned char Fonts[2][8] = {
{0},
{0, 31, 0, 31, 0, 31, 0, 31}
};
This works in C++:
unsigned char foo [2][8] = {
{},
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}
};
Here, foo[0]
is zero-initialized as defined by the C++ standard (§8.5.5 - default initialization for POD types is zero-initialization). For non-POD-types the default constructor is called.