What does "char (* a) [12]" mean?

Is it from standard C?

+3
source share
4 answers

Since declarations in C follow the rules of operator precedence (for example, subscribing to an array is evaluated indirectly), you will need parsers to declare pointers to array types.

In many cases, there is no practical advantage when using simple char *, except that this is a way to ensure the size of the array, especially when using the function as a parameter:

void foo(char bar[42]);

equivalently

void foo(char *bar);

and accepts any char *, whereas

void foo(char (*bar)[42]);

will only accept pointers to size arrays 42.

bar , char *

char *baz = *bar;

baz[13] (*bar)[13].

+3

C, cdecl, :

~$ cdecl
Type `help' or `?' for help
cdecl> explain char (*a)[12];
declare a as pointer to array 12 of char
+15

Pointer to an array of 12 characters.

+3
source

a- A pointer pointing to array of 12 characters.

+1
source

Source: https://habr.com/ru/post/1749343/


All Articles