1

这似乎是一个很棒的地方。我的问题是,我在 memmove() 的这个实现中移动了什么值(或多少字节)?

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

在下一个示例中,它说我正在移动 11 个字节。但是是什么让它有 11 个字节呢?有人可以解释一下吗?

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

谢谢!

编辑:顺便说一句,字符串长度为 33,包括终止空字符。

4

3 回答 3

1

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.

于 2011-10-29T02:22:14.993 回答
0

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

于 2011-10-29T02:21:13.427 回答
0

第三个参数定义要复制多少字节;在第一个示例中,您应该定义要复制的字节数。

于 2011-10-29T02:27:21.507 回答