c - Why does `memmove` use `void *` as parameter instead of `char *`? -


the definition of c library function memmove following:

void* memmove(void *s1, const void *s2, size_t n) {     char *sc1;     const char *sc2;      sc1 = s1;     sc2 = s2;     ... } 

i'm wondering why need use void* , const void* parameters' type. why not directly char* , const char*?

update

int test_case[] = {1, 2, 3, 4, 5, 6, 7, 8, 10};  memmove(test_case+4, test_case+2, sizeof(int)*4); 

output: test_case = {1, 2, 3, 4, 3, 4, 5, 6, 10}

void * generic pointer type. memmove supposed manipulate memory regardless of type of objects in memory.

similarly memcpy. compare strcpy uses char * parameters because it's supposed manipulate strings.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -