Is this from the C standard?
4 Answers
If you're confused by a C declaration, you can use the cdecl
program to explain it:
~$ cdecl
Type `help' or `?' for help
cdecl> explain char (*a)[12];
declare a as pointer to array 12 of char

- 87,747
- 23
- 163
- 198
-
3cool, I did not know it! (I have my notebook with a small list of strange decls I tend to forget) +1 – ShinTakezou Jun 10 '10 at 07:57
A pointer to an array of 12 characters.

- 278,309
- 50
- 514
- 539
-
-
4@dan, if you're going to be pedantic, you should also be right. "An object declared as type char is large enough to store any member of the basic execution character set." (§6.2.5 of C99) A `char` can't hold (e.g.) an arbitrary Unicode character, but it can hold basic characters as defined by C. – Matthew Flaschen Jun 10 '10 at 06:12
-
@dan04: Considering `char` automatically converts its value into the corresponding ASCII character, I'm pretty sure that qualifies it as a character at least in some sense. – Maulrus Jun 10 '10 at 06:13
-
@Maulrus: There really isn't any ASCII conversion. You might be confused by the 'x' syntax, but 'x' is just a literal integer value of type int. Conversion of the 'x' from ASCII or any other encoding the file happens to have occurs at compilation/translation time. – Peaker Jun 10 '10 at 06:26
-
`char` is just a small integer type. `int8_t` in most implementations. It's often used for ASCII characters (or nowadays, UTF-8 code units) but doesn't have to be. A `char` array could even represent pixels in a bitmap. – dan04 Jun 10 '10 at 06:41
-
3@dan, I didn't say otherwise. Yes, `char` holds numbers, but the standard says, "The three types char, signed char, and unsigned char are collectively called the character types." so I still think your distinction is both pedantic and incorrect. – Matthew Flaschen Jun 10 '10 at 07:01
-
-
2C defines character as either "a member of a set of elements used for the organization, control, or representation of data" or a "single-byte character: bit representation that fits in a byte". Your question doesn't say which you mean. If the former, you don't say which set we're dealing with. If the latter, you don't say the encoding. So your question doesn't make sense. – Matthew Flaschen Jun 10 '10 at 07:51
-
1multibyte encodings made all this a possible debate! "¿Cómo estás?" contains 11 characters for a human (do not count the space, it is not a character for a human), or indeed 9, not counting punctuation marks. In ISO 8859 encodings, C counts 12 char, which is correct (space included). If the string is UTF-8 encoded or any other non-single byte encoding, the count is "of course" wrong. Nonetheless, that "wrong count" is always made of char(acter)s from the C point of view. – ShinTakezou Jun 10 '10 at 08:05
-
Fair enough, my understanding of it was obviously wrong. Thanks for the clarification peaker! – Maulrus Jun 10 '10 at 13:52
Because declarations in C follow the operator precedence rules (ie array subscription is evaluated before indirection), you'll need parens to declare pointers to array types.
In many use cases, there's not really any practical benefit over using a plain char *
, except that it's a way to enforce the array size, especially when used as a function parameter:
void foo(char bar[42]);
is equivalent to
void foo(char *bar);
and accepts any char *
, whereas
void foo(char (*bar)[42]);
will only accept pointers to arrays of size 42
.
As accessing the elements of bar
in the latter case is cumbersome, it might be a good idea to immediately define an equivalent char *
in the function body
char *baz = *bar;
so that you can use direct subscription baz[13]
instead of (*bar)[13]
.

- 164,997
- 36
- 182
- 240
a
is a pointer pointing to an array of 12 characters
.

- 65,327
- 90
- 227
- 319
-
It is a **pointer**. You could say an *array* pointer, but it is useless to add an adjective to pointer when you add *pointing to* afterwards. Writting *character pointer* is misleading. – Didier Trosset Jun 10 '10 at 11:01
-
Your answer is wrong, Benjamin, and shows a misunderstanding of pointers. Please fix it, or better yet delete it since correct answers were already given. First of all, just like in `int a`, here `a` is a variable. What type has this variable? "a pointer to an array of 12 elements". Just like in `char* a`, `a` is "a pointer to a char". Second, you can't make one pointer point to another kind of data without casting (well, in C you can with `void*` only, but this is off the point) – Eli Bendersky Jun 18 '10 at 05:07