C memcmp() Function

You are Here:

C memcmp() Function

The memcmp() function compares the first n bytes of memory area str1 and memory area str2.


C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "ABCD"; char str2[] = "abcd"; int res = memcmp(str1, str2, 3); if(res == 0) printf("str1 is equal to str2"); else if(res > 0) printf("str1 is greater than str1"); else printf("str1 is less than str2"); return 0; }


str1 is less than str2


int memcmp(const void *str1, const void *str2, size_t n)

Parameter Values

str1RequiredA block of memory.
str2RequiredA block of memory.
nRequiredNumber of bytes to be compared.

Return Value

+iveIf str1 is greater than str2
0If str1 is equal to str2
-iveIf str1 is less than str2


Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author