Can I create variables during compiling time in in c++

I appreciate it if someone has the answer.

Can I create variables during compiling time in in c++. I have an array with 729 elements. I want to divide it into 81 arrays each consists of 9 elements. I do not want to declare 81 arrays. I am thinking maybe there is a way I can use a "for" loop to do it for me.
The title of your post poses an XY problem (see: http://xyproblem.info/ ). Fortunately you have provided a little information about your actual problem.

Consider declaring an array of arrays. int x[81][9]; // 81 arrays of 9 int;
Or using pointer arithmetic.
1
2
int* block_n(int* x, int n) 
{ return x + (n * block_size) }
More sophisticated solutions are available if required.
Last edited on
If you already have defined and initialized the array of 729 elements ...

 
int x[729] = { 1, 2, 3, ..., 728, 729 };

... then you can easily split it up into an array of arrays without having to touch the sequence of values.

 
int x[81][9] = { 1, 2, 3, ..., 728, 729 };
Last edited on
Topic archived. No new replies allowed.