Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language compares two strings for equality. Please explain in detail.
C language compares two strings for equality. Please explain in detail.

C language string is a series of characters, that is, arranged in char type. A character is of type char. How to represent a series of characters? Represented by the address of their first character, because the strings are also consecutively arranged on the address. And use \0, which is physically all 0 bits in a byte, to indicate the end of the string. So "abcde" is 'a' 'b' 'c' 'd' 'e' '\0' in space. The parameters of strcmp are all char*, which are pointers to characters. The principle is to point from two pointers. The addresses are compared until one of them is \0. Determine whether they are equal or not. The implementation is to subtract each character. Simple == compares whether the addresses of the strings are equal. This comparison not only cannot compare whether the two strings are equal, but also to be equal, the two strings must point to the same address.