<分区>
我开始了解将一维数组传递给函数的两种方法。
void bubbleSort(int *arr, int len); //Here I am passing arr as a pointer to the array.
void bubbleSort(int arr[], int len); //Here I am not sure.. but arr is a const pointer.
这两个函数的调用是一样的,那么这两个函数定义有什么区别,有什么好处呢?
<分区>
我开始了解将一维数组传递给函数的两种方法。
void bubbleSort(int *arr, int len); //Here I am passing arr as a pointer to the array.
void bubbleSort(int arr[], int len); //Here I am not sure.. but arr is a const pointer.
这两个函数的调用是一样的,那么这两个函数定义有什么区别,有什么好处呢?
最佳答案
实际传递的值是一样的。在后一种情况下,您不能在函数 bubbleSort
中更改 arr
的值,因为 arr
的类型是“数组”和数组名称有点像常量指针。
关于c - 将数组传递给函数 (C/CPP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286623/