C++ two-dimensional array occupied space size and first address

Hits: 0

#include<iostream>
using namespace std;
int main()
{
    int arr[2][3] = {
        {1,2,3},
        {4,5,6}
    };
    cout << "The size of the two-dimensional array is:" << sizeof (arr) << endl ;
     cout << "The size of a row of the two-dimensional array is:" << sizeof (arr[ 0 ]) << endl ;
     cout < < "The size of the two-dimensional array elements is:" << sizeof (arr[ 0 ][ 0 ]) << endl ;
     cout << "The number of rows in the two-dimensional array is:" << sizeof (arr) / sizeof (arr [ 0 ]) << endl ;
     cout <<"The number of columns of a two-dimensional array is:" << sizeof(arr[ 0 ]) / sizeof (arr[ 0 ][ 0 ]) << endl ;
     //For decimal, add (int) in front of it 
    cout << "The first address of the two-dimensional array is:" << arr < < endl ;
     cout << "The first address of the first line of the two-dimensional array is:" << arr[ 0 ] << endl ;
     cout << "The first address of the first element of the two-dimensional array is:" << &arr[ 0 ][ 0 ] << endl ;
     cout << "The first address of the second element of the two-dimensional array is:" << &arr[0][1] << endl;
}

You may also like...

Leave a Reply

Your email address will not be published.