Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Why is similar string comparison giving different result?

c string

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 nick112


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 29 May 2017 - 06:17 PM



I am learning about strings in C. And got puzzled with string comparison behavior.

I have declared 3 strings as below.

char *str1="String1";
char *str2="String1";
char str3[] = "String1";

comparing str1==str2 giving true where as str1==str3 giving false. 

Can anybody help me, why is it so?


Complete runnable code is here http://onlinegdb.com...fork/B1mPNLqbZ 


Thanks in advance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download