2 answers
Best answer
strcmp compares two character strings ( str1 and str2 ) using the standard EBCDIC collating sequence.
Mr C.
· 20 Jun 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Answer: strcmp(s1, s2) compares two strings character by character and returns 0 if they are equal, a negative value if s1 comes first, and a positive value if s1 comes later.
It is declared in string.h. Characters are compared one by one using their character codes (ASCII on most computers) until a difference or the null character '\0' is reached.
- Returns 0 → both strings are identical.
- Returns < 0 →
s1is less thans2(e.g. "apple" vs "banana"). - Returns > 0 →
s1is greater thans2.
if (strcmp(pass, "abc123") == 0)
printf("Password correct");It is used because == compares only the addresses of two strings, not their contents.
Doubtly AI
· 24 Oct 2026
AI-verified · Oct 2026
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.