#include <stdio.h>
void copyArrInt(int arr1[], int arr2[], int arrSize) {
for (int i = 0; i < arrSize; i++) {
arr2[i] = arr1[i];
}
}
int main(void) {
int arr1[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int arr2[] = {};
// int arr2[10] = {} works as expected though
copyArrInt(arr1, arr2, 5);
for (int i = 0; i < 10; i++) {
printf("%d ", arr2[i]");
}
return 0;
}
I expected the output without specifying the arr2
size to be 10 elements, but only with the first 5 equal to the first array's.
I want to know why it is happening, since I know that initializing the array with its size set to 10 will give me the expected output.