a[0] is same as &a[0] and a (for 2 dim array) ?

black_snail 2002-09-09 02:20:55
#include <stdio.h>
#define FORMAT "%d,%d\n"
main()
{
static int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23};
int *p;
A. for (p=a[0];p<a[0]+12;p++)
B. for (p=a[0];p<(&a[0])+12;p++)
C. for (p=a[0];p<a+12;p++)


{
if ((p-a[0])%4==0) printf("\n");
printf("%4d",*p);
}

}

A is working (Display the array value )
B and C not working , Why , I thought a[0] is same as &a[0] and a (for 2 dim array)
...全文
74 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
木棉花大榕树 2002-09-09
  • 打赏
  • 举报
回复
B. Because a[0] is a type int*, &a[0] is a type int **.
C. I think (*a)=a[0] not (*a)=a[0][0],so a+12=a[12],!=a[0][12]
black_snail 2002-09-09
  • 打赏
  • 举报
回复
blh(老猫) , your answer is quite reasonable
blh 2002-09-09
  • 打赏
  • 举报
回复
首先肯定的是a[0]、 &a[0]和 a的地址是相同的,只是随后的+12是不同的
a[0] + 12 是以a[0]地址为起始,按照a[0]的长度为单位+12
而&a[0]和 a只是以&a[0]和 a地址为起始,简单的将地址+12
这是编译器来决定的
black_snail 2002-09-09
  • 打赏
  • 举报
回复
printf("%o,%o,%o",&a[0],a[0],a) shows the same value , Why ?
dcyu 2002-09-09
  • 打赏
  • 举报
回复
a[0] is not same as &a[0] and a (for 2 dim array)
&a[0] is same as a ,but both of them are not same as a[0],
so y r wrong!

69,391

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧