invalid conversion from 'int' to 'int*' [-fpermissive] on passing array

前端 未结 3 413
野趣味
野趣味 2021-01-25 03:26

I am new to C++ language and I have no idea of pointers and their usage. I\'m facing the error \"[Error] invalid conversion from \'int\' to \'int*\' [-fpermissive]\"

3条回答
  •  猫巷女王i
    2021-01-25 03:48

    You need to pass a pointer to the first element of array. Change midd (ax [10], asize ) to midd (ax, asize ).

    In function signature

    double midd(int arr[10],int size);
    

    parameter int arr[10] is equivalent to int *arr

    double midd(int *arr,int size);
    

    Therefore, midd expects its first argument of the type int *. In function call midd (ax, asize ), ax will decay to int *.

提交回复
热议问题