Copyright © tutorialspoint.com

# C - memcmp function

## Synopsis:

    #include <stdio.h>

    int memcmp(const void* cs, const void* ct, int n);

## Description:

The memcmp function compares the first n bytes from cs and ct and returns a value indicating their relationship as follows:

## Return Value

- if Return value if < 0 then it indicates cs less than ct

- if Return value if > 0 then it indicates ct is less than cs

- if Return value if = 0 then it indicates cs is equal to ct

## Example

    #include <stdio.h>

    int main() {
      char hexchars [] = "0123456789ABCDEF";
      char hexchars2 [] = "0123456789abcdef";
      char i;

      i = memcmp (hexchars, hexchars2, 16);

      if (i < 0)
        printf ("hexchars < hexchars2\n");
      else if (i > 0)
        printf ("hexchars >  hexchars2\n");
      else
        printf ("hexchars == hexchars2\n");

      return 0;
    }

It will proiduce following result:

    hexchars < hexchars2

Copyright © tutorialspoint.com