When you passed the array variable (typically the address of the first element), the function would just let's say copy its value into a local variable of its own, and all it does is changing the value of that variable which doesn't affect the original arr you want to change. In order to do that you need to access the data pointed to by that address and change each number value at a time, you could iterate over it or use something like memcpy() , that'll do the job.
#include <stdio.h>
#include <string.h>
void modifyArray(int arr[]) {
int tempArr[] = {6, 7, 8, 9, 10}; /* Creating a temporary array to copy from */
size_t sizeOfArray = 5; /* This is just the number of elements in the array */
memcpy(arr, tempArr, sizeof(int) * sizeOfArray); /* copying from the tempArr to the original arr */
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
modifyArray(arr);
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]); // Outputs 1 2 3 4 5, not 6 7 8 9 10
}
}
there are many other ways to do it ofc. hope I helped somehow.