char *p = "abc";
char *q = "abc";
if (p == q)
printf ("equal");
else
printf ("not equal");
Output:
equal
Is it compiler specific, or is it defined somewhere in the standards to be as expected behaviour.
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.
The compiler is permitted to ‘coalesce’ string literals, but is not required to.
From 6.4.5/6 String literals:
In fact, the compiler could merge the following set of literals:
such that
qmight point ‘inside’ the string pointed to byp(ie.,q == &p[3]).