int colors[][3] = {
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 0, 0, 255 },
{ 253, 7, 210 }
};
int (*EXCLUSIVE_COLOR)[3];
I have a two-dimensional array to store some color values.
I have a 2nd array, which I am using to assign an "EXCLUSIVE_COLOR" from the first colors array.
What is the best method to assign a null or empty value to the "EXCLUSIVE_COLOR" array to be used upon initialization and when the "EXCLUSIVE_COLOR" is unset?
Initially I tried just assigning a default value to the array upon initialization:
int (*EXCLUSIVE_COLOR)[3] = {0,0,0};
//Produces an error: scalar object ‘EXCLUSIVE_COLOR’ requires one element in initializer
int (*EXCLUSIVE_COLOR)[3] = {0};
//assigns non-zero values to all three elements
I know that I can add a "dummy" record to the colors array to reference, when there isn't an "EXCLUSIVE_COLOR" set.
int colors[][3] = {
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 0, 0, 255 },
{ 253, 7, 210 },
{ 0, 0, 0, } //dummy record
};
int (*EXCLUSIVE_COLOR)[3] = &colors[4];
However I wanted to know if there was a cleaner way to be able to assign an empty value to reference when a color is not set, and when the array is initialized.
int* EXCLUSIVE_COLOR = {0,0,0};read my comment or the edit at the end of Edgar's answer