对memcpy()和memset()的疑问 [英] Doubt in memcpy() and memset()

查看:88
本文介绍了对memcpy()和memset()的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道一些情况,何时使用memcpy()和什么时候

到memset();


提前付款..

Hi,
I want to know some of the situations , when to use memcpy() and when
to memset();

Thanx in Advance..

推荐答案



Shhnwz.a写道:

Shhnwz.a wrote:



我想知道一些情况,何时使用memcpy()和什么时候

来memset();


Thanx in Advance ..
Hi,
I want to know some of the situations , when to use memcpy() and when
to memset();

Thanx in Advance..



NAME

memcpy - copy memory区域


名称

memset - 用一个恒定字节填充内存


家庭作业!


[提示:手册很有趣]


Tom

NAME
memcpy - copy memory area

NAME
memset - fill memory with a constant byte

HOMEWORKALITY!

[hint: man pages are fun]

Tom


Shhnwz.a写道:
Shhnwz.a wrote:

我想知道一些情况,何时使用memcpy()和什么时候

到memset();
I want to know some of the situations , when to use memcpy() and when
to memset();



你能说出他们的描述吗?


memcpy(void * s1,const void * s2,size_t n);


...将s2

指向的对象中的n个字符复制到s1指向的对象中。如果在重叠的对象之间发生复制

,则行为未定义。


memset(void * s,int c,size_t n);


...将c的值(转换为无符号字符)

复制到指向的对象的前n个字符中

to by s。


使用适合您情况的任何一种。


-

Chris" Perikles凯" Dollin

这里没有人正是他出现的。 G''kar,/ Babylon 5 /

Can''t you tell from their descriptions?

memcpy( void *s1, const void *s2, size_t n );

... copies n characters from the object pointed to by s2
into the object pointed to by s1. If copying takes place
between objects that overlap, the behaviour is undefined.

memset( void *s, int c, size_t n );

... copies the value of c (converted to an unsigned char)
into each of the first n characters of the object pointed
to by s.

Use whichever one fits your situation.

--
Chris "Perikles triumphant" Dollin
"No-one here is exactly what he appears." G''kar, /Babylon 5/


Chris Dollin写道:
Chris Dollin wrote:

>

memset(void * s,int c,size_t n);


...复制c的值(转换为unsigned char)

到对象的前n个字符中每个字符

到s。
>
memset( void *s, int c, size_t n );

... copies the value of c (converted to an unsigned char)
into each of the first n characters of the object pointed
to by s.



顺便说一句,我我对第二个参数的类型感到困惑。

为什么不使用(unsigned char)类型?

memset(void * s,unsigned char c,size_t n) ;


谢谢。

By the way, I''m puzzled about the type of the second parameter.
Why not use (unsigned char) type?
memset(void *s, unsigned char c, size_t n);

Thanks.


这篇关于对memcpy()和memset()的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆