Inilializing array
Hello.
I want to do something like this:
int testArray[3][2] = boolVariable? {{0, 0}, {1, 0}, {1, 0}} : {{1, 0}, {1, 1}, {0, 0}};
But I get errors. Why I can't use "shorthand if" there?
I tried this:
1 2 3 4
|
int testArray[3][2] = {{0, 0}, {1, 0}, {1, 0}};
if (boolVariable)
testArray = {{1, 0}, {1, 1}, {0, 0}};
|
still errors.
I hate to assign array values one by one. Is there a solution for me?
Thanks
Last edited on
Well, you could try this:
1 2 3 4
|
int tmp_array_1[3][2] = {{0, 0}, {1, 0}, {1, 0}};
int tmp_array_2[3][2] = {{1, 0}, {1, 1}, {0, 0}};
int result[3][2];
memcpy(result, boolVariable ? tmp_array_1 : tmp_array_2, sizeof(result));
|
Topic archived. No new replies allowed.