有以下程序   main( )   { int m=3,n=4,x;    x=-m++;    x=x+8/++n;    printf("%d\n",x);   }   程序运行后的输出结果是

admin2006-08-25  14

问题 有以下程序
  main(  )
  { int m=3,n=4,x;
     x=-m++;
     x=x+8/++n;
     printf("%d\n",x);
  }
  程序运行后的输出结果是

选项 A、3
B、5
C、-1
D、-2

答案D

解析 本题涉及运算符的优先级,见程序中,第一行为数据定义及初始化,第二行“++”的优先级高于“—”所以,运行第二行后x的值为—4,第三行中“/”的优先级高于“++”,所以,先进行除法运算,再对n进行“++”运算,得出结果应为-4+8/4 = -2。
转载请注明原文地址:https://kaotiyun.com/show/x4Hp777K
0

相关试题推荐
最新回复(0)