c语言二维字符串初始化,C中的二维字符数组初始化

Eric Leschin..

9

如何创建包含字符指针的数组大小5:

char *array_of_pointers[ 5 ]; //array size 5 containing pointers to char

char m = 'm'; //character value holding the value 'm'

array_of_pointers[0] = &m; //assign m ptr into the array position 0.

printf("%c", *array_of_pointers[0]); //get the value of the pointer to m

如何创建指向字符数组的指针:

char (*pointer_to_array)[ 5 ]; //A pointer to an array containing 5 chars

char m = 'm'; //character value holding the value 'm'

*pointer_to_array[0] = m; //dereference array and put m in position 0

printf("%c", (*pointer_to_array)[0]); //dereference array and get position 0

如何创建包含字符指针的2D数组:

char *array_of_pointers[5][2];

//An array size 5 containing arrays size 2 containing pointers to char

char m = 'm';

//character value holding the value 'm'

array_of_pointers[4][1] = &m;

//Get position 4 of array, then get position 1, then put m ptr in there.

printf("%c", *array_of_pointers[4][1]);

//Get position 4 of array, then get position 1 and dereference it.

如何创建指向2D数组字符的指针:

char (*pointer_to_array)[5][2];

//A pointer to an array size 5 each containing arrays size 2 which hold chars

char m = 'm';

//character value holding the value 'm'

(*pointer_to_array)[4][1] = m;

//dereference array, Get position 4, get position 1, put m there.

printf("%c", (*pointer_to_array)[4][1]);

//dereference array, Get position 4, get position 1

你可能感兴趣的:(c语言二维字符串初始化)