From the cppreference.com documentation

int strcmp( const char *lhs, const char *rhs );

Return value

  • Negative value if lhs appears before rhs in lexicographical order.

  • Zero if lhs and rhs compare equal.

  • Positive value if lhs appears after rhs in lexicographical order.

As you can see it just says negative, zero or positive. You can't count on anything else.

The site you linked isn't incorrect. It tells you that the return value is < 0, == 0 or > 0 and it gives an example and shows it's output. It doesn't tell the output should be 111.

Answer from bolov on Stack Overflow
🌐
PHP
php.net › manual › en › function.strcmp.php
PHP: strcmp - Manual
The result is +1 or -1 no matter how big is the difference between the numerical values. <?php $str = array('','a','afox','foxa'); $size = count($str); echo '<pre>'; for($i=0; $i<$size; $i++) { for($j=$i+1; $j<$size; $j++) { echo '<br>('.$str[$i].','.$str[$j].') = '.strcmp($str[$i], $str[$j]); echo '<br>('.$str[$j].','.$str[$i] .') = '.strcmp($str[$j], $str[$i]); } } echo '</pre>'; ?> In Apache/2.4.37 (Win32) OpenSSL/1.1.1 PHP/7.2.12 produces the following results: (,a) = -1 //comparing with an empty string produces the length of the NON-empty string (a,) = 1 // ditto (,afox) = -4 // ditto (afox,) = 4 // ditto (,foxa) = -4 // ditto (foxa,) = 4 // ditto (a,afox) = -3 // The identical BEGINNING part ("a") is trunkated from both strings.
🌐
Programiz
programiz.com › c-programming › library-function › string.h › strcmp
C strcmp() - C Standard Library
The strcmp() function is defined in the string.h header file. #include <stdio.h> #include <string.h> int main() { char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd"; int result; // comparing strings str1 and str2 result = strcmp(str1, str2); printf("strcmp(str1, str2) = %d\n", result); // comparing strings str1 and str3 result = strcmp(str1, str3); printf("strcmp(str1, str3) = %d\n", result); return 0; } Output ·
🌐
MathWorks
mathworks.com › matlab › language fundamentals › data types › characters and strings
strcmp - Compare strings - MATLAB
tf = strcmp(s1,s2) compares s1 and s2 and returns 1 (true) if the two are identical and 0 (false) otherwise. Text is considered identical if the size and content of each are the same. The return result tf is of data type logical.
🌐
TechOnTheNet
techonthenet.com › c_language › standard_library_functions › string_h › strcmp.php
C Language: strcmp function (String Compare)
/* Example using strcmp by TechOnTheNet.com */ #include <stdio.h> #include <string.h> int main(int argc, const char * argv[]) { /* Create a place to store our results */ int result; /* Create two arrays to hold our data */ char example1[50]; char example2[50]; /* Copy two strings into our data arrays */ strcpy(example1, "C programming at TechOnTheNet.com"); strcpy(example2, "C programming is fun"); /* Compare the two strings provided */ result = strcmp(example1, example2); /* If the two strings are the same say so */ if (result == 0) printf("Strings are the same\n"); /* If the first string is less than the second say so (This is because the 'a' in the word 'at' is less than the 'i' in the word 'is' */ if (result < 0) printf("Second string is less than the first\n"); return 0; } When compiled and run, this application will output: Second string is less than the first ·
🌐
freeCodeCamp
freecodecamp.org › news › strcmp-in-c-how-to-compare-strings-in-c
strcmp in C – How to Compare Strings in C
April 27, 2023 - Therefore, the function strcmp() returns a negative value indicating that the first string is less than the second string. Based on the value in result, it prints String 1 is less than string 2..
🌐
W3Schools
w3schools.com › c › ref_string_strcmp.php
C string strcmp() Function
The strcmp() function compares two strings and returns an integer indicating which one is greater.
Find elsewhere
🌐
IBM
ibm.com › docs › en › i › 7.4.0
strcmp() — Compare Strings
We cannot provide a description for this page right now
🌐
SAS
support.sas.com › documentation › onlinedoc › ccompiler › doc700 › html › lr1 › z2056611.htm
Function Descriptions : strcmp
The return value from strcmp is 0 if the two strings are equal, less than 0 if str1 compares less than str2 , and greater than 0 if str1 compares greater than str2 .
🌐
GeeksforGeeks
geeksforgeeks.org › c language › strcmp-in-c
strcmp() in C %%sep%% %%sitename%% - GeeksforGeeks
December 13, 2025 - Explanation: In this code, strcmp compares the two strings first_str ("zfz") and second_str ("gfg"). Since 'z' has a greater ASCII value than 'g', strcmp returns a positive value, indicating the strings are unequal.
🌐
PVS-Studio
pvs-studio.com › en › docs › warnings › v698
V698. Functions of strcmp() kind can return any values, not only -1, 0, or 1.
V698. The analyzer has detected a comparison of the result of strcmp() or similar function to 1 or -1. The C/C++ language specification, however, says that the strcmp() function can return any positive or...
🌐
TutorialsPoint
tutorialspoint.com › home › c_standard_library › c standard library strcmp function
C Standard Library strcmp Function
August 29, 2012 - On execution of above code, we get the following result − · Strings are not equal(case-insensitive). Below the example create the strings of different size and check its comparison using strcmp().
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › strcmp in c
strcmp in C | String Comparison Function with Examples
February 5, 2025 - The strings are not equal. Result: 32 ... strcmp() returns a non-zero value (32 in this case) because the ASCII values of 'a' (97) and 'A' (65) are different.
🌐
O'Reilly
oreilly.com › library › view › c-in-a › 0596006977 › re217.html
strcmp - C in a Nutshell [Book]
December 16, 2005 - The strcmp() function compares the strings, one character at a time. As soon as it finds unmatched characters in corresponding positions in the two strings, the string containing the greater unsigned character value at that position is the greater string...
Authors   Peter PrinzTony Crawford
Published   2005
Pages   618
🌐
BeginnersBook
beginnersbook.com › 2017 › 11 › c-strcmp-function
C strcmp() Function with example
#include <stdio.h> #include <string.h> int main () { char str1[20]; char str2[20]; int result; //Assigning the value to the string str1 strcpy(str1, "hello"); //Assigning the value to the string str2 strcpy(str2, "hEllo"); result = strcmp(str1, str2); if(result > 0) { printf("ASCII value of first unmatched character of str1 is greater than str2"); } else if(result < 0) { printf("ASCII value of first unmatched character of str1 is less than str2"); } else { printf("Both the strings str1 and str2 are equal"); } return 0; }
🌐
The Open Group
pubs.opengroup.org › onlinepubs › 009604499 › functions › strcmp.html
strcmp
Upon completion, strcmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, respectively.
🌐
Cppreference
en.cppreference.com › w › c › string › byte › strcmp
strcmp - cppreference.com
The sign of the result is the sign of the difference between the values of the first pair of characters (both interpreted as unsigned char) that differ in the strings being compared.