指向指针的指针不会啊
#include <stdio.h>int main()
{
char *cBooks[] = {
"《C程序设计语言》",
"《C专家编程》",
"《C和指针》",
"《C陷阱与缺陷》",
"《C Primer Plus》",
"《带你学C带你飞》"};
char **byFishC;
char **jiayuLoves;
int i;
byFishC = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
printf("FishC出版的图书有:%s\n", *byFishC);
printf("小甲鱼喜欢的图书有:\n");
for (i = 0; i < 4; i++)
{
printf("%s\n", *jiayuLoves);
}
return 0;
}
请问 char **byFishC;
char **jiayuLoves;
int i;
byFishC = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
这一段什么意思啊?有点蒙 char *cBooks[] //一个指针数组。
char **byFishC //一个指针的指针变量,你可以理解为一个二组数组指针。
char **jiayuLoves //一个存放四个指针的指针元素的数组。
byFishC = &cBooks //把"《带你学C带你飞》"的地址赋给它
jiayuLoves = &cBooks //同上
jiayuLoves = &cBooks;//同上
jiayuLoves = &cBooks; //同上
jiayuLoves = &cBooks; //同上 char *cBooks[]
// *cBooks[]名指针数组,本质是数组,数组中存放的是指针
char **byFishC
// **byFishC名双重指针,本质是指针,指针指向的还是一个指针
char **jiayuLoves
// **jiayuLoves名双重指针数组,本质是数组,数组中存放的是双重指针
byFishC = &cBooks
//取cBooks的地址,并赋值给byFishC。换句话说byFishC这个变量中的内容是cBooks的地址
jiayuLoves = &cBooks
//取cBooks的地址,并赋值给jiayuLoves。换句话说jiayuLoves这个数组中的内容是cBooks的地址
指向指针的指针就是一个二维数组罢了,说的那么绕口,用二维数组的概念去理解一下代码就都明朗了 你买了本自己喜欢的书 (你可以把这本书就当做一个内存地址)
你是这本书的所有人~(你可以看做 你自己就是指向这个内存地址的指针~)
这时候你朋友也喜欢这本书,想找你借阅,那肯定是通过你问你同不同意借阅~而不是直接去拿那本书~(你可以把这个朋友当做指向指针的指针)
这时候你们看的是不是同一本书~(同一个内存地址~) char **byFishC; //双重指针,指向一个指针的指针
char **jiayuLoves;//双重指针数组,其中每一个元素都是一个双重指针
int i;
byFishC = &cBooks; //将指针数组第5个元素的地址赋给byFishC
jiayuLoves = &cBooks; //将指针数组第1个元素的地址赋给jiayuLoves
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
jiayuLoves = &cBooks;
//指针数组cBooks[]保存的是每一个字符串的首地址
页:
[1]