I have this code:
char *name = "George"
if(name == "George")
printf("It's George")
I thought that c strings could not be compared with ==
sign and I have to use strcmp
. For unknown reason when I compile with gcc (version 4.7.3) this code works. I though that this was wrong because it is like comparing pointers so I searched in google and many people say that it's wrong and comparing with ==
can't be done. So why this comparing method works ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…