用指针读取二维数组的两种方式

2019-07-31  本文已影响0人  mark_x

include <stdio.h>

int main()
{
int i;
char *array[4] = {
"Hello!",
"How are you?",
"Fine, thanks. And you?",
"I'm fine, too"
}; // 定义了一个指针数组,有四个指针,每个指针指向一个字符串(指向一个字符数组的首元素的地址)

// 用字符数组名(指针数组)读取
for (i = 0; i < 4; i++)
{
    printf("%s\n", array[i]);
}


// 用数组指针读取
char *(*p2)[4] = &array;
for (i = 0; i < 4; i++)
{
    printf("%s\n", (*p2)[i]);
}

return 0;

}

第二个看不懂。。。烦气。。!!!

上一篇 下一篇

猜你喜欢

热点阅读