for loop on different variables names

后端 未结 4 825
野趣味
野趣味 2021-01-27 12:09

I am programing for a while but for this i couldn\'t find an answer yet .

lets say i want to run on a loop when i change the names of the variables.

lets say i h

4条回答
  •  梦如初夏
    2021-01-27 12:43

    Make it an array! Using different names differentiated by a number is a bad practice:

    int ran[3];
    
    for (int k = 0; k < 3; k++)
    {
        ran[k % 3] = k;
    }
    

    Now, instead of using ran1, or ran2, you would use ran[1] or ran[2]. Arrays in C are quite confusing, and they are distinct from pointers.

提交回复
热议问题