c strcmp

#include <stdio.h>
#include <string.h>

int main() {
    char str1[] = "Hello";
    char str2[] = "World";

    int result = strcmp(str1, str2);

    if (result == 0) {
        printf("Both strings are equal.\n");
    } else if (result < 0) {
        printf("String 1 is lexicographically smaller than String 2.\n");
    } else {
        printf("String 1 is lexicographically greater than String 2.\n");
    }

    return 0;
}
  1. Include necessary header files: stdio.h for standard input/output functions and string.h for string-related functions.

  2. Declare two character arrays (str1 and str2) and initialize them with the strings "Hello" and "World".

  3. Use the strcmp function to compare the two strings (str1 and str2). The result is stored in the variable result.

  4. Check the value of result:

  5. If result is 0, it means both strings are equal.
  6. If result is negative, it means str1 is lexicographically smaller than str2.
  7. If result is positive, it means str1 is lexicographically greater than str2.

  8. Print the appropriate message based on the comparison result.

  9. Return 0 to indicate successful execution of the program.