++运算符在前和在后我都懂,但下面这几个式子还是很费解,求解释#include <iostream.h>
int fun(int x, int y)
{
return x*y;
}
void main()
{
int k=5;
cout<<fun(++k,++k)<<endl; k=5;
cout<<fun(k++,k++)<<endl; k=5;
         cout<<fun(++k,k++)<<endl;
  
         k=5;
         cout<<fun(k++,++k)<<endl; k=5;
cout<<(++k)*(++k)<<endl; k=5;
cout<<(k++)*(k++)<<endl; k=5;
cout<<(++k)*(k++)<<endl; k=5;
cout<<(k++)*(++k)<<endl;
}
答案依次是: 42 25 30 36 49 25 36 36

解决方案 »

  1.   

    ++或--运算符放在变量前面,那么在运算之前,变量先完成自增或自减运算;如果运算符放在后面,那么自增自减运算是在变量参加表达式的运算后再运算。对于函数fun来说,其两个参数为两个表达式
      

  2.   

    int k=5;
    cout<<fun(++k,++k)<<endl;k=5;
    cout<<fun(k++,k++)<<endl;k=5;
      cout<<fun(++k,k++)<<endl;
       
      k=5;
      cout<<fun(k++,++k)<<endl;上面几个我调试了一下发现结果是:49 30 35 42
      

  3.   

    stdcall cdecl fastcall thiscall naked call 全来一次 其实这种问题很蛋疼
      

  4.   

    以上是我VC6编译的++的使用说明我都懂,可放在这个里面又有很多疑惑
    比如这个:
    k=5;
    cout<<(++k)*(++k)<<endl;
    算得49怎么搞的,我怎么想都是6*7=42的VC6编译下是按什么顺序算的?
      

  5.   

    以上是我VC6编译的++的使用说明我都懂,可放在这个里面又有很多疑惑
    比如这个:
    k=5;
    cout<<(++k)*(++k)<<endl;
    算得49怎么搞的,我怎么想都是6*7=42的VC6编译下是按什么顺序算的?
    //////////////////////////////////////////////////////////楼主需要搞清楚计算的先后顺序:
    “()”的运行级别要高于“*”, 所以:
    第一步(++k)执行后,k=6 ; 
    第二步(++k)执行后,k=7;
    第三步才是 7*7 = 49;