I was just reading some code and found that the person was using arr[-2]
to access the 2nd element before the arr
, like so:
|a|b|c|d|e|f|g|
^------------ arr[0]
^---------- arr[1]
^---------------- arr[-2]
Is that allowed?
I know that arr[x]
is the same as *(arr + x)
. So arr[-2]
is *(arr - 2)
, which seems OK. What do you think?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…