why cant we pass &array to function where &array[0] is possible

后端 未结 6 1575
攒了一身酷
攒了一身酷 2021-01-25 18:34
void fun(int* array){}  


int main(){

int array[]={1,2,3};
fun(&array);----->(1)//error in this line
return 0;
}

error: cannot convert â

6条回答
  •  旧时难觅i
    2021-01-25 19:27

    You have mismatching types.

    The function expects *int (pointer to an int).

    array and &array[0] is of that type, *int.

    But &array is of type int(*)[3] (pointer to an array of 3 ints).

提交回复
热议问题