C Strings Comparison with Equal Sign -


i have code:

char *name = "george"  if(name == "george")    printf("it's george") 

i thought c strings not compared == sign , have use strcmp. unknown reason when compile gcc (version 4.7.3) code works. though wrong because comparing pointers searched in google , many people it's wrong , comparing == can't done. why comparing method works ?

i thought c strings not compared == sign , have use strcmp

right.

i though wrong because comparing pointers searched in google , many people it's wrong , comparing == can't done

that's right too.

so why comparing method works ?

it doesn't "work". appears working.

the reason why happens compiler optimization: 2 string literals identical, compiler generates 1 instance of them, , uses same pointer/array whenever string literal referenced.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -