I have a 2-d array, we call arr2[3][3]. If I want to store the first row of arr2 to a new array, we call arr1[3], how would I do that?
I tried int arr1[] = arr2[0]. But it doesn't work.
I have a 2-d array, we call arr2[3][3]. If I want to store the first row of arr2 to a new array, we call arr1[3], how would I do that?
I tried int arr1[] = arr2[0]. But it doesn't work.
You can either assign each element using a loop
for(int i =0; i < 3; i++)
arr1[i] = arr2[0][i];
Alternatively, you can use memcpy.
memcpy(&arr1[0], &arr2[0][0], sizeof(int) * columnSize);
Make sure that the array being copied to has enough space when doing this approach, otherwise funky stuff will happen (easier to overlook here than with iteration)