Typedef for 2 dimensional array in C Typedef for 2 dimensional array in C arrays arrays

Typedef for 2 dimensional array in C


Try this:

typedef char board[10][10];

Then you can define new array as this:

board double_array = {"hello", "world"}; 

It's the same with:

char double_array[10][10] = {"hello", "world"};


Type Definition Statement

The type definition statement is used to allow user defined data types to be defined using other already available data types.

Basic Format:

typedef existing_data_type new_user_defined_data_type;

So , yours should be :

typedef char board[10][10];

You can use it as Yu Hao has said OR you can also use it with char pointers to define a 2D array like this :

typedef char *board[10];

And then you can do as described by YU Hao.In such a way you need not hard code the number of characters you want to use for the strings.