
有以下程序#include<stdio.h> main() { int c[6]={10,20,30,40,50,60},*p,*s; p=a; s=&c[5]; printf("%d\
#include<stdio.h>main(){intc[6]={10,20,30,40,50,60},*p,*s;p=a;s=&c[5];printf("%d\n",s...
#include<stdio.h>
main()
{ int c[6]={10,20,30,40,50,60},*p,*s;
p=a; s=&c[5];
printf("%d\n",s-p);
}为什么答案是5?不是50么? 展开
main()
{ int c[6]={10,20,30,40,50,60},*p,*s;
p=a; s=&c[5];
printf("%d\n",s-p);
}为什么答案是5?不是50么? 展开
2个回答
展开全部
你这里输出的是二个指针的地址之差,c[5]与c[0]的地址之差(以int的存储空间大小为单位),所以是5。若想得到所期望的50,就该是二个单元存储的值的差。此时的输出语句应该写为:
#include<stdio.h>
main()
{ int c[6]={10,20,30,40,50,60},*p,*s;
p=a; s=&c[5];
printf("%d\n",*s-*p);
}
#include<stdio.h>
main()
{ int c[6]={10,20,30,40,50,60},*p,*s;
p=a; s=&c[5];
printf("%d\n",*s-*p);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询