C - memmove() function - How many bytes am I moving in this implementation?

799 Views Asked by At

This seems to be a great place. My question is, what value (or how many bytes) am I moving in this implementaion of memmove()?

int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+15,str+20,/*?*/);
puts (str);
return 0;
}

In the next example it says I am moving 11 bytes. But what makes it 11 bytes? Could somebody explain?

int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+20,str+15,11); //source and destination are reversed
puts (str);
return 0;
}

Thanks!

Edit: BTW, the string length is 33 including the terminating null character.

3

There are 3 best solutions below

3
On

The final argument to memmove() is the number of bytes to move - in this case 11

0
On

The third parameter of memmove specifies the number of bytes to move, so in your second example you are moving 11 bytes. Your first example should not compile because you will have a syntax error on the line that calls memmove.

2
On

Third parameter defines how many bytes to copy; in the first example you should be defining how many bytes to copy.