Understanding Char Array equality in C

后端 未结 5 921
忘了有多久
忘了有多久 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:51

    if(a == b) will compare the addresses stored in a and b pointers.

    strcmp(a, b) will compare character by character of the contents stored at a and b addresses. It returns 0 if both contents are same (case sensitive). otherwise difference in ASCII values of the characters

    if(*a == *b) will compare the first characters (i.e. char at 0th position) of both array.

    Hope it helps !!

提交回复
热议问题