I am trying to understand complicated declarations in C, and I wrote a sample function that takes as argument an array of integers of length 10 and returns a pointer to an array of length 10 of integers –
int (*x(int arr[10]))[10] {
for (int i = 0; i < 10; i++) {
arr[i] = 1;
}
return &arr[10];
}
int main() {
int array[10];
for(int i = 0; i < 10; i++) {
printf("%d ", array[i]);
}
printf("n");
x(array);
for (int i = 0; i < 10; i++) {
printf("%d", array[i]);
}
}
But I do not understand what to put as return. &arr[10]
gives an error cannot convert 'int*' to 'int (*)[10]' in return
. &arr
also gives the same error. So what should be the appropriate return statement?