On this page
  1. memcmp
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

memcmp

Prev: memset | Up: string.h | Next: memchr
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — memcmp
Tags: #public #prog #c #stdlib #string #tier/core


Include

#include <string.h>

Signature & Overview

int memcmp(const void *lhs, const void *rhs, size_t n);

Compares n raw bytes as unsigned char; returns <0, 0, or >0.

Notes & Pitfalls

Example

#include <assert.h>
#include <string.h>

int main(void) {
    assert(memcmp("abc", "abc", 3) == 0);
    assert(memcmp("abc", "abd", 3) < 0);
}

Linked from

Related notes