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

后端 未结 6 1619
攒了一身酷
攒了一身酷 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条回答
  •  甜味超标
    2021-01-25 19:31

    try this:

    void fun(int* array){} // int *array is integer pointer so it can point to int not the int pointer. 
    
    int main(){
    
    int array[]={1,2,3};
    fun(array); //remove &. now *array of pm point to array[0] i.e int.
    return 0;
    }
    

提交回复
热议问题