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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值