Cannot convert from 'int *' to 'int []'?

Viewed 21701

I know this might be a common question but I have tried to search but still cannot find a clear answer.

I have the following code:

int* f() {
    int a[] = {1,2,3};
    return a;
}

int main() {

    int a[] = f(); // Error here

    getch();
    return 0;
}

This code produces the error message: "Cannot convert from 'int *' to 'int []'"

I found this quite strange because I have read that pointer and array are similar. For example, we can use a[i] instead of *(a + i). Can anyone give me a clear explanation, please?

4 Answers
Related