简体   繁体   中英

how to use memcpy in 3d arrays in C

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 ?

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM