How can I (deeply) copy an array in C?

Referring to http://www.devx.com/tips/Tip/13291 , he says that I can use memcpywith the copy size defined sizeof(), however, is this not an array pointing to a pointer?

Besides repeating in an array, how can I use memcpyfor a deep copy of an array?

Thank!

+3
source share
3 answers

A multidimensional array is contiguous. An array of pointers (pointers ...) is another thing (and each sub-pointer should be selected / copied / freed by itself).

Do not confuse the fact that in most situations a one-time array and one pointer can be used interchangeably, since they are not technically the same.

+6

int weekly_hours[5][5]; 25 . , memcpy .

+8

, :

  • - , .
  • ( "" ) , . , .
  • sizeof() , . sizeof() , .
  • sizeof() , (.. 4 32- ).
+4

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


All Articles