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?
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];
© 2022 - 2024 — McMap. All rights reserved.
a
is an array in this context, not a pointer to one. – Pleading