what is the difference between the below declarations?
char *argv[];
and
char *(argv[]);
I think it is same according to spiral rule.
As written, the parentheses make no difference.
The so-called spiral rule falls out of this simple fact of C grammar: postfix operators such as ()
and []
have higher precedence than unary operators like *
, so expressions like *f()
and *a[]
are parsed as *(f())
and *(a[])
.
So given a relatively complex expression like
*(*(*foo)())[N]
it parses as
foo -- foo
(*foo) -- is a pointer (parens force grouping)
(*foo)() -- to a function
(*(*foo)()) -- returning a pointer (parens force grouping again)
(*(*foo)())[N] -- to an array
*(*(*foo)())[N] -- of pointer