String as an array index

An 3["XoePhoenix"]array index has the type of an array of characters. Can we do this in C? Isn't it true that the array index must be an integer?

What does it mean 3["XeoPhoenix"]?

+3
source share
3 answers

3["XoePhoenix"]matches with "XoePhoenix"[3], so it will evaluate char 'P'.

The array syntax in C is nothing more than another way of writing *( x + y ), where xboth yare auxiliary expressions before and inside the brackets. Due to the commutativity of the addition, these auxiliary expressions can be exchanged without changing the value of the expression.

, 3["XeoPhoenix"] *( 3 + "XeoPhoenix" ), 3 , , , char . * , 'P'.

"XeoPhoenix"[ 3 ] *( "XeoPhoenix" + 3 ), , .

+5

3["XeoPhoenix"] "XeoPhoenix"[3] 4- i.e 'P'.

a[i] i[a] .

a[i] = *(a + i) = *(i + a) = i[a] 
+5

C . , .

0

All Articles