Multidimensional C Arrays -


i have 4 arrays contains values. array should contain these 4 arrays shown in code:

static const long one_color[2] = { rgb_black, rgb_white }; static const long two_color[4] = { rgb_white, rgb_red, rgb_green, rgb_blue }; static const long three_color[8] = { rgb_black, rgb_red, rgb_green, rgb_blue,     rgb_cyan, rgb_yellow, rgb_magenta, rgb_white }; static const long four_color[16] = { rgb_white, rgb_red, rgb_green, rgb_blue,     rgb_cyan, rgb_yellow, rgb_magenta, rgb_dark_red, rgb_dark_green,     rgb_dark_blue, rgb_light_blue, rgb_light_green, rgb_orange, rgb_lime,     rgb_pink, rgb_lila };  //this array should contain other arrays static const long color_array = {one_color,two_color, three_color,     four_color }; 

my problem access values in array. thought can receive value of rgb_black color_array[0][0]. tried pointer constructions, doesn't work neither :(

it sounds want array of pointers arrays.

static const long *const color_array[4] = {     one_color, two_color, three_color, four_color }; 

both const recommended: first const means pointer constant arrays, second const means array of pointers is, itself, constant.

you can access elements you'd think, color_array[1][3] == rgb_blue, et cetera.

note

i being little sloppy terminology. not getting pointers arrays pointers first element in each array. operations, in c, array , pointer first element interchangeable.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -