Important Points
- This function takes two strings and a number num as arguments and compares at most the first num bytes of both strings.
- num should be at most equal to the length of the longest string. If num is defined as greater than the string length then the comparison is done till the null character (‘\0’) of either string.
- This function compares the two strings lexicographically. It starts comparison from the first character of each string. If they are equal to each other, it continues and compares the next character of each string, and so on.
- This process of comparison stops until a terminating null character of either string is reached or the num characters of both strings match.
Related Articles
std::strncmp() in C++
std::strncmp() function in C++ lexicographically compares not more than count characters from the two null-terminated strings and returns an integer based on the outcome. This function is a Standard Library function that is defined in <cstring> header file in C++.
Contact Us