In 3["XoePhoenix"], array index is of type array of characters. Can we do this in C? Isn’t it true that an array index must be an integer?
What does 3["XeoPhoenix"] mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
3["XoePhoenix"]is the same as"XoePhoenix"[3], so it will evaluate to the char'P'.The array syntax in C is not more than a different way of writing
*( x + y ), wherexandyare the sub expressions before and inside the brackets. Due to the commutativity of the addition these sub expressions can be exchanged without changing the meaning of the expression.So
3["XeoPhoenix"]is compiled as*( 3 + "XeoPhoenix" )where the string decays to a pointer and3is added to this pointer which in turn results in a pointer to the 4th char in the string. The*dereferences this pointer and so this expression evaluates to'P'."XeoPhoenix"[ 3 ]would be compiled as*( "XeoPhoenix" + 3 )and you can see that would lead to the same result.