C Programming/string.h/strncmp

strncmp is a standard-library function that compares two strings up to a specified length. The function is declared in string.h, and is compatible with the following prototype:

The function compares the strings using a lexicographical ordering, but never examines more than  characters. It returns zero if the strings are equal, or if their first  characters are equal; otherwise, it returns a negative integer if   is less than , and a positive integer if   is greater than. A simple implementation might be as follows:

In practice, however, real implementations are significantly optimized.