You declared a pointer to a whole array
short (*pas)[3] = &tell;
So to get the pointed object (array) you have to dereference the pointer like
*pas
Now this expression yields a lvalue reference to the array tell
. So you may apply the subscript operator to access elements of the array
cout << (*pas)[2] << endl;
The postfix subscript operator has a higher priority than the unary operator *
.
that is this expression
*pas[2]
is equivalent to the expression
*( pas[2] )
It means you are trying to access an object (array) beyond the allocated array that results in undefined behavior.
If you had a two=dimensional array like for example
short tell[3][3] =
{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
And initialized the pointer pas
like
short (*pas)[3] = tell;
the the expression pass[2]
would yield the third element of the array that is { 7, 8, 9 }
In this case you may apply one more subscript operator to access an element of the array like for example
pass[2][2]
that contains the value 9
.
The above expression also can be rewritten without the subscript operator like
*( *( pass + 2 ) + 2 )