C++ Cstring Strcmp()

C++ cstring strcmp()  in the cstring header that compares two null-terminated strings lexicographically.

Syntax:

int strcmp(const char* str1, const char* str2);

Parameters:

str1: Pointer to the first string.

str2: Pointer to the second string.

Return Value:

< 0: str1 is less than str2

0: str1 is equal to str2

> 0: str1 is greater than str2

Usage Example:

#include
#include

int main() {
    const char* str1 = "apple";
    const char* str2 = "banana";

    int result = strcmp(str1, str2);
    if (result < 0) {
        std::cout << "str1 is less than str2" << std::endl;
    } else if (result == 0) {
        std::cout << "str1 is equal to str2" << std::endl;
    } else {
        std::cout << "str1 is greater than str2" << std::endl;
    }

    return 0;
}

Key Points:

Case-sensitive comparison.

Ensure both strings are null-terminated to avoid undefined behavior.

Email : mishramanishd245@gmail.com