string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -



string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

what difference between "some" == "some\0" , strcmp("some","some\0") in c++?

why if("some" == "some\0") returns false , if(!strcmp("some","some\0")) returns true ?

see next diagram. shows 2 strings in memory, content in box, beside box you'll see address of each one.

when you're doing if("some" == "some\0") comparing addresses. translated if (0xdeadbeef == 0x0badcafe) false.

when utilize strcmp, compare content of each box until reach \0 in each of them. that's why sec test returns true.

if alter first test if("some" == "some") compiler may potentially see same strings , store them once. means test transform if (0x0badcafe == 0x0badcafe) true.

c++ string comparison

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -