I know that a declaration like
int* a[5];
declares a
as an array of 5 pointers to int
. But how do I deduce this, just by using the C++ Standard?
Just see the grammar of C++.
ptr-declarator:
noptr-declarator
ptr-operator ptr-declarator
noptr-declarator:
declarator-id attribute-specifier-seqopt
noptr-declarator parameters-and-qualifiers
noptr-declarator [ constant-expressionopt] attribute-specifier-seqopt
( ptr-declarator )
and
ptr-operator:
* attribute-specifier-seqopt cv-qualifier-seqopt
& attribute-specifier-seqopt
&& attribute-specifier-seqopt
nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt
Thus this declaration
int* a[5];
may be written like
int ( * ( ( a )[5] ) );
That is ( ( a )[5] )
is a noptr-declarator and ( * ( ( a )[5] ) )
is ptr-operator ptr-declarator.
A declaration of a pointer to an array of 5 integers will look like
int ( *a )[5];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With