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 26 27 28 29 30 31
|
#include<iostream>
using namespace std;
int main (){
int myArray[5] = {62, 45, 95, 85, 0};
int array2D[3][3] = {{1, 5, 6},
{45, 65, 65},
{78, 10, 99}};
//Test #1, printing using (*) works fine on 1D arrays
cout << "\nHere, I will print data from the 1D array:"
<< "\nData on [0]: " << *(myArray)
<< "\nData on [4]: " << *(myArray+4);
//Test #2, printing using (*) does not work with 2D arrays
cout << "\n\nI will print a 2D array"
<< "\n\nFirst, the data on [1][2]: " << *(array2D+1)
<< "\nNow, the data on [2][2]: " << *(array2D+4);
//Test #3, to see the address
cout << "\n\nI will print the address of the same two values we used before"
<< "\nAddress of [1][2]: " << (array2D+1)
<< "\nAddress of [2][2]: " << (array2D+4);
return 0;
}
|