In C, copying such an array is not possible. What for? and best hack

int x[10],y[10];
x = y;

I mean a simple hack that will allow me to get this effect.

+3
source share
3 answers

You can wrap them in structto use a simple assignment:

struct foo { int a[10]; } x, y;
x = y;

But really just use it memcpy.

+19
source

You need to use memcpy(or memmove) to transfer the memory block.

memcpy(x, y, sizeof(x));
+11
source

memcpy() for (i = 0; < 10; ++)

+1

Source: https://habr.com/ru/post/1730732/


All Articles