Slide 1 / 14
Copying arrays — you can't use `=`
Unlike simple variables, you cannot copy one array to another with =. You must copy element by element with a loop.
code_example.cpp
int src[5] = {1, 2, 3, 4, 5};
int dst[5];
// WRONG — does NOT copy the array!
// dst = src; // compile error
// CORRECT — copy element by element
for (int i = 0; i < 5; i++)
dst[i] = src[i];