C program to compare strings using strcmp() function
Given two strings and we have to compare them using strcmp() function in C language.
C language strcmp() function
strcmp() function is used to compare two stings, it checks whether two strings are equal or not.
strcmp() function checks each character of both the strings one by one and calculate the difference of the ASCII value of the both of the characters. This process continues until a difference of non-zero occurs or a \0 character is reached.
Return value/result of strcmp() function:
- 0 : If both the strings are equal
- Negative : If the ASCII value of first unmatched character of first string is smaller than the second string
- Positive : If the ASCII value of first unmatched character of first character is greater than the second string
C program/example for strcmp() function
Output