1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
using namespace std;
// better to use arr[] or arr* as it makes it clearer
// that the function has no idea what size the array is!
void show(int arr[2], int actualSize) {
cout << "arr = ";
for(int i = 0; i < actualSize; ++i)
cout << " " << arr[i];
cout << "\n";
}
int main() {
int var1[1] = {3};
int var2[2] = {3,1};
int var4[4] = {3,1,4,1};
int var8[8] = {3,1,4,1,5,9,2,6};
show(var1, 1);
show(var2, 2);
show(var4, 4);
show(var8, 8);
return 0;
}
|