how to use memcpy in 3d arrays in C
c
Solution
can i use `memcpy(y, x, sizeof(x))`?
Yes.
after that can I access the elements of array `y` same as that of `x`?
Yes.
Note that this approach breaks down if you allocate the array dynamically (e.g. using `malloc()`). If you do that, `sizeof()` will no longer give you the size of the array (it will give the size of the pointer), and you'll have to keep track of the array dimensions yourself.
Problem
I have a 3 dimensional array `int32_t x[1024][4][256]`. I need to copy all the elements of the array to another array of same type and size `int32_t y[1024][4][256]`. Can i use `memcpy(y, x, sizeof(x));`? after that can I access the elements of array `y` same as that of `x`?