Need to use a running variable name in c++

Hello experts,

Maybe this is a trivial question but I haven't figured it out. I need to reference variable names based on a loop counter. A stupid example would be the "code" below.

I could do this with the Me() function in VB. How do I do this in c++ ?
int array1[10];
int array2[10];
for (i=1;i != 3;i++)
       array'i'[i] = i
       //Here I would like to put the number 1 in array1[1] and 2 in array2[2]

Open in new window

Who is Participating?
you cant have running variable names afaik but you can use pointer arrays to have a similar effect

int arr0[5] = { 0 };
int arr1[5] = { 0 };
int arr2[5] = { 0 };
int arr3[5] = { 0 };
int arr4[5] = { 0 };

int * arr[5] = { arr0, arr1, arr2, arr3, arr4 };

for (i=1;i != 3;i++)
       (*(arr+i))[i] = i;
please check the following code.
for (i=1; i <= 3; i++)
       array1[i] = i;
       array2[i] = i;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.