Char array subscript warning

后端 未结 3 1313
粉色の甜心
粉色の甜心 2020-12-07 01:51

when I use char array subscript as in this example:

int main(){
    char pos=0;
    int array[100]={};

    for(pos=0;pos<100;pos++)
        printf(\"%i\\         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 02:57

    Because native char can be either unsigned or signed.

    Note that it's perfect legal to use negative subscript. For instance:

    int arr[10];
    int *ptr = arr[5];
    

    Now I can use ptr[-1] which is equivalent to arr[4]. If char happens to be unsigned in the implementation, it can never be a negative value.

提交回复
热议问题