What is the difference between taking as a function argument an int pointer or an int array in C++?
void arrayFunction1(int * x) {
for(int i = 0; i < 10; i++) {
cout << x[i] << endl;
}
}
void arrayFunction2(int x[]) {
for(int i = 0; i < 10; i++) {
cout << x[i] << endl;
}
}
int main() {
int dstdata[10];
arrayFunction1(dstdata);
arrayFunction2(dstdata);
return 0;
}
Both results look the same to me.
int[]as a parameter type does not mean "array ofint", it means "pointer toint". Your prototypes are equivalent, and both function arguments are equivalent to passing&dstdata[0].sizeof(x)gives unexpected results.std::array. You should start with STL and go to pointers, C-arrays and other advanced stuff after you've learned the basics. A C++ array can be copied and passed to functions. Either learn C or C++, not both at the same time. That's confusing and leads to very bad practices.std::arrayinstead of C arrays.