Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of 10 pointer to char[2][2] array

Tags:

arrays

c

pointers

For a pointer to an [2][2] char array, I can write: char (*p)[2][2] and for an array of 10 elements of type pointer to char: char* p[10].

How do you write an array of 10 elements of type pointer to char[2][2]?

Why does this statement have a syntax error?

char (*)[2][2] p[10];
like image 574
Masoud Fard Avatar asked Aug 28 '26 02:08

Masoud Fard


1 Answers

You need to use

char (*p[10])[2][2];

But you should really use a typedef, as these decl. can become exceedingly complicated:

typedef char (*ptr_arr)[2][2]; // our pointer-to-char[2][2]
ptr_arr p[10]; // now we have a clean syntax, this is an array of pointers to char[2][2]

You can also use the new using in C++11 like

using ptr_arr = char(*)[2][2];
ptr_arr p[10];
like image 194
vsoftco Avatar answered Sep 01 '26 12:09

vsoftco