What exactly does the following do (and what memory does it allocate?)
>
int (*varname)[4][4];
It declares varname as a pointer to an 4-element array of
4-element arrays of ints.
--
"I've given vodka years and years of oral pleasure, and it's done the
same for me. And neither of us has really taken any steps to take the
relationship to the `next level.'"
--Jeremy Hunt
What exactly does the following do (and what memory does it allocate?)
>
int (*varname)[4][4];
C++'s declaration syntax (inherited from C) is
indeed a nightmare. You should definitely read
Chapter 3 of Peter van der Linden's "Expert C
Programming", a wonderful and hilarious book which
gives a nice decoder ring for making sense
of these things (the one you mentioned isn't
anywhere near as bad as it gets when pointers
to functions get involved).
Also, check out SPECS, which is a syntax-change-only
reskinning of C++ (with an amusing nod to C++'s original
name). I'm not suggesting you program in it, but
it's nice to realize that the declaration syntax
is historical cruft from a failed experiment, not
something inherently unsound about the language.
Comment