
库 #include <memory.h> 包含了基本的内存操作。虽然不严格属于字符串函数,但这些函数的原型在 #include <string.h> 中声明。
这些内存操作如下:
| void *memchr (void *s, int c, size_t n); | 在缓冲区中搜索字符。 |
| int memcmp (void *s1, void *s2, size_t n); | 比较两个缓冲区。 |
| void *memcpy (void *dest, void *src, size_t n); | 将一个缓冲区复制到另一个缓冲区。 |
| void *memmove (void *dest, void *src, size_t n); | 将一定数量的字节从一个缓冲区移动到另一个缓冲区。 |
| void *memset (void *s, int c, size_t n); | 将缓冲区的所有字节设置为给定字符。 |
请注意,在所有情况下,都是复制字节的内存。sizeof() 函数再次派上了用场。
| memcpy(dest, src, SIZE); | 复制字符(字节) |
| memcpy(idest, isrc, SIZE*sizeof(int)); | 复制整数数组 |
立即学习“C语言免费学习笔记(深入)”;
立即学习“C语言免费学习笔记(深入)”;
memmove() behaves in exactly the same way as memcpy() except, that the source and destination locations may overlap.
立即学习“C语言免费学习笔记(深入)”;
立即学习“C语言免费学习笔记(深入)”;
memcmp() is similar to strcmp() except here, unsigned bytes are compared and returns less than zero if si is less than s2 etc.
例如,
char src[SIZE], dest[SIZE]; int isrc[SIZE], idest[SIZE];











