Array indexing starting at a number not 0

后端 未结 13 2368
Happy的楠姐
Happy的楠姐 2021-02-20 04:02

Is it possible to start an array at an index not zero...I.E. you have an array a[35], of 35 elements, now I want to index at say starting 100, so the numbers would be a[100], a[

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 04:50

    You're not very clear on exactly how you want to use these arrays, but its easy enough to set up a single contiguous array that can appear to be two different arrays:

    int   ram[15000]; 
    int * sram=&ram[0];
    int * bram=&ram[10000];
    

    I used the &foo[xxx] notation just to make it explicit what you're doing. Anyway, you can now use ram to index anywhere into the entire array, or sram and bram to index into particular parts.

提交回复
热议问题