开发者

does memcpy params have to be of the same type?

开发者 https://www.devze.com 2023-01-02 06:00 出处:网络
I was reading that memcpy takes the number of bytes from a source location and adds it to a destination location. Does this mean that memcpy could possibly 开发者_开发技巧change datatype entirely ??

I was reading that memcpy takes the number of bytes from a source location and adds it to a destination location. Does this mean that memcpy could possibly 开发者_开发技巧change datatype entirely ??

memcpy(DoubleOne, CharTwo, strlen(CharTwo));

considering that both values are empty still.


Yes, memcpy doesn't care about the types. (It converts both its parameters to void pointers anyway)

It doesn't "change datatype" as much as it just writes char data into a double array (in your case) and hopes it makes sense.


Yes, they dont have to.

int test = 3;
char dest[sizeof(int)];

memcpy(&dest[0], &test, sizeof(int));

Is valid c(++).

0

精彩评论

暂无评论...
验证码 换一张
取 消