(a) 一个整型数(An integer)
(b) 一个指向整型数的指针(A pointer to an integer)
(c) 一个指向指针的的指针,它指向的指针是指向一个整型数(A pointer to a pointer to an integer)
(d) 一个有10个整型数的数组(An array of 10 integers)
(e) 一个有10个指针的数组,该指针是指向一个整型数的(An array of 10 pointers to integers)
(f) 一个指向有10个整型数数组的指针(A pointer to an array of 10 integers)
(g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数(A pointer to a function that takes an integer as an argument and returns an integer)
(h) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数( An array of ten pointers to functions that take an integer argument and return an integer )
答案:
(a) int a; // An integer
(b) int *a; // A pointer to an integer
(c) int **a; // A pointer to a pointer to an integer
(d) int a[10]; // An array of 10 integers
(e) int *a[10]; // An array of 10 pointers to integers
(f) int (*a)[10]; // A pointer to an array of 10 integers
(g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
(h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer
(1)指针数组:它实际上是一个数组,数组的每个元素存放的是一个指针类型的元素。
int* arr[8];
//优先级问题:[]的优先级比*高
//说明arr是一个数组,而int*是数组里面的内容
//这句话的意思就是:arr是一个含有8和int*的数组
(2)数组指针:它实际上是一个指针,该指针指向一个数组。
int (*arr)[8];
//由于[]的优先级比*高,因此在写数组指针的时候必须将*arr用括号括起来
//arr先和*结合,说明p是一个指针变量
//这句话的意思就是:指针arr指向一个大小为8个整型的数组。
四、函数指针、函数指针数组、函数指针数组的指针
1.函数指针
void test()
{
printf("hehe\n");
}
//pfun能存放test函数的地址
void (*pfun)();
函数指针的形式:类型(*)( ),例如:int (*p)( ).它可以存放函数的地址,在平时的应用中也很常见。
2.函数指针数组
形式:例如int (*p[10])( );
因为p先和[ ]结合,说明p是数组,数组的内容是一个int (*)( )类型的指针
函数指针数组在转换表中应用广泛
3.函数指针数组的指针
指向函数指针数组的一个指针,也就是说,指针指向一个数组,数组的元素都是函数指针
void test(const char* str)
{
printf("%s\n", str);
}
int main()
{
//函数指针pfun
void (*pfun)(const char*) = test;
//函数指针的数组pfunArr
void (*pfunArr[5])(const char* str);
pfunArr[0] = test;
//指向函数指针数组pfunArr的指针ppfunArr
void (*(*ppfunArr)[10])(const char*) = &pfunArr;
return 0;
}
https://blog.youkuaiyun.com/cherrydreamsover/article/details/81741459 数组和指针的区别与联系(详细)
https://blog.youkuaiyun.com/qq_27678917/article/details/70224813 C++中指针和引用的区别
https://blog.youkuaiyun.com/qq_39539470/article/details/81273179 C++中指针和引用的区别详解版
https://www.cnblogs.com/yinzm/p/6510938.html 指针和引用的区别
https://www.cnblogs.com/gxcdream/p/4805612.html 浅谈指针和引用的区别
https://www.cnblogs.com/x_wukong/p/5712345.html 传指针和传指针引用的区别/指针和引用的区别(本质)