输出二维数组任一行任一列元素的值
main(){inta[3][4]={{1,3,5,7},{9,11,13,15},{17,19,21,23}};int(*p)[4],i,j;p=a;scanf(“%d...
main( )
{
int a[3][4]={ {1,3,5,7}, {9,11,13,15},
{17,19,21,23} };
int (*p)[4], i, j ;
p=a;
scanf(“%d , %d”, &i,&j);
printf(“a[%d][%d]=%d\n”,i,j,*(*(p+i)+j));
}
问:p必须定义为(*p)[4]?可以直接定义为*p?为什么?定义为(*p)[4],和*p有什么区别? 展开
{
int a[3][4]={ {1,3,5,7}, {9,11,13,15},
{17,19,21,23} };
int (*p)[4], i, j ;
p=a;
scanf(“%d , %d”, &i,&j);
printf(“a[%d][%d]=%d\n”,i,j,*(*(p+i)+j));
}
问:p必须定义为(*p)[4]?可以直接定义为*p?为什么?定义为(*p)[4],和*p有什么区别? 展开
展开全部
(*p)[4]是列数为4的二维数组,你可以理解为有p这么一个数组,他里面的每一个元素都是一个列数为4的数组
*p是一维数组
你的a是二维的,所以要这么定义才能p=a;
*p是一维数组
你的a是二维的,所以要这么定义才能p=a;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int (* pz)[2]; // pz points to an array of 2 ints
This statement says that pz is a pointer to an array of two ints. Why the parentheses? Well, [ ] has a higher precedence than *. Therefore, with a declaration such as
int * pax[2];
you apply the brackets first, making pax an array of two somethings. Next, you apply the *, making pax an array of two pointers. Finally, use the int, making pax an array of two pointers to int. This declaration creates two pointers to single ints, but the original version uses parentheses to apply the * first, creating one pointer to an array of two ints.
This statement says that pz is a pointer to an array of two ints. Why the parentheses? Well, [ ] has a higher precedence than *. Therefore, with a declaration such as
int * pax[2];
you apply the brackets first, making pax an array of two somethings. Next, you apply the *, making pax an array of two pointers. Finally, use the int, making pax an array of two pointers to int. This declaration creates two pointers to single ints, but the original version uses parentheses to apply the * first, creating one pointer to an array of two ints.
参考资料: <c primer plus fifth edition > charpter 10
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询