有以下程序 #include main() { int y=1,x,a[]={2,4,6,8,10},*p; p=&a[1]; for( x=0; x<3; x++ ) y=y+*( p+x ); printf( "%d\n", y ); } 程序

admin2019-07-14  16

问题 有以下程序
#include
main()
{  int  y=1,x,a[]={2,4,6,8,10},*p;
p=&a[1];
for( x=0; x<3; x++ )  y=y+*( p+x );
printf( "%d\n", y );
}
程序运行后的输出结果是

选项 A、17
B、19
C、18
D、20

答案B

解析 本题通过语句"p=&a[1]将指针变量p指向了存储单元a[1],即使得p[0]的值为4。然后通过3次for循环,x=0时,*(p+x)=*p=a[1]=4所以y=1+4=5;x=1时,*(p+x)=*(p+1)=a[2]=6,所以y=5+6=11;x=2时,*(p+x)=*(p+2)=a[3]=8,所以y=11+8=19。因此B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/7ARp777K
0

最新回复(0)