当我找到一个数组的长度时,如果在一个单独的函数中使用它,它会一直返回2。但是,如果我在主函数中找到长度,它会正确找到长度。如果有人可以提供帮助,那么非常感谢你。我是一个c ++ noob
void printLength(int inputArray[]) {
cout << "This is my value when finding the length in ANOTHER function: " << sizeof(inputArray)/sizeof(int) << endl;
}
int main()
{
int testArray[] = { 1, 2, 3, 4, 5, 6 };
printLength(testArray);
cout << "This is my value when finding the length in the main function: " << sizeof(testArray)/sizeof(int) << endl;
}
这是我的输出
This is my value when finding the length in ANOTHER function: 2
This is my value when finding the length in the main function: 6