Understanding Char Array equality in C

后端 未结 5 867
忘了有多久
忘了有多久 2021-01-19 13:47

Sorry in advance for the ignorance. I don\'t fully understand how to compare char arrays in C. I was originally comparing two char arrays in c with the simple ==

5条回答
  •  离开以前
    2021-01-19 14:50

    I would recommend to use strcmp because it compares the contents of the strings while == compares the address of the first elements in the strings.

    Also, strcmp will tell you the relative ordering of the strings rather than simply if they are equal.

提交回复
热议问题