I'm still learning C++. Currently I'm learning arrays and want to get length of an array. I know to get length of an array I have to type:
int length = (sizeof(array)/sizeof(*array));
It works very well. But, when I make a method to get length that I named as getLength() it doesn't work. Here my code:
#include <iostream>
using namespace std;
int array[5] = {1,2,3,4,5};
int getLength(int arg[]){
return(sizeof(arg)/sizeof(*arg));
}
int main(){
//array length
cout << "Displaying array length" << endl;
cout << getLength(array) << endl;
system("pause");
}
That should returns 5, but it returned 1. If I use previous way, it returns 5, even they have same code.
Thanks for helps.