What is 0[p] doing?

This question already has an answer here:

  • With arrays, why is it the case that a[5] == 5[a]? 17 answers

  • The C Standard defined the operator [] this way:

    Whatever a and b are a[b] is considred as *((a)+(b))

    And that's why 0[p] == *(0 + p) == *(p + 0) == p[0] which is the first element of the array.


    0[p] is equivalent to p[0] . Both are converted as

    0[p] = *(0+p) and p[0] = *(p+0)
    

    From above statements both are equal.


    0[p]
    

    in 0[p] = 42;

    is equivalent to p[0]

    + operation is commutative and we have:

    p[0] == *(p + 0) == *(0 + p) == 0[p]
    
    链接地址: http://www.djcxy.com/p/86716.html

    上一篇: 数组]在C ++中

    下一篇: 什么是0 [p]在做什么?