I stumbled upon code containing something like:
char c = "abc"[1];
and it compiles and runs fine with gcc! c will be 'b' after this expression.
Is this standard to index literal strings or is it mere luck that it works?
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.
Of course it is, a string literal is of array type. It is converted to a pointer to
charin the expression and is like an any pointer tochar.and
are equivalent.