void main() {
if("a" == "a")
printf("Yes, equal");
else
printf("No, not equal");
}
Why is the output No, not equal?
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.
What you are comparing are the two memory addresses for the different strings, which are stored in different locations. Doing so essentially looks like this:
Use the following code to compare two string values:
Additionally,
"a" == "a"may indeed return true, depending on your compiler, which may combine equal strings at compile time into one to save space.When you’re comparing two character values (which are not pointers), it is a numeric comparison. For example: