传递给函数的数组大小

时间:2016-09-26 16:15:50

标签: c++ arrays

#include <iostream>
using namespace std;

int binarySearch(int inArray[], double targetVal)
{
  int lowIndex = 0;
  int upIndex = (sizeof(inArray)/sizeof(inArray[0]));
  int middleIndex = (lowIndex + upIndex) / 2;

  cout << sizeof(inArray) << endl;

  cout << inArray[3] << endl;

  // cout << upIndex << endl;

}

int main()
{
  int a[4] = {0 , 1 , 3, 5};

  cout << sizeof(a) << endl;

  // cout << sizeof(a)/sizeof(*a) << endl;

  binarySearch(a , 3);
}

这是相关代码。在main()中,sizeof(a)输出16.在binarySearch()中,sizeof(inArray)输出8.有人可以向我解释为什么会有区别吗?数组a应该与inArray相同?

0 个答案:

没有答案