[讨论]关于复合运算符的一个有趣现象

mcmay 2007-12-09 02:24:06
//testing compound arithematic operators

#include <stdio.h>
#include <stdlib.h>

int main(void){

int a = 5, b = 6;

printf("\na = %d, b = %d\n",a,b);
printf("\na +=b = %d\ta += b + 1 = %d\ta += (b+1) = %d\t(a += b) + 1 = %d\n",
a += b, a +=b + 1, a += (b+1), (a += b) + 1);
system("PAUSE");
return 0;
}
...全文
83 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ltc_mouse 2007-12-09
  • 打赏
  • 举报
回复
这有个关于函数参数求值顺序的简单程序,你可以参考下:

#include <stdio.h>
#include <stdlib.h>
static int func1( )
{
printf("func1 called.\n");
return 1;
}
static int func2( )
{
printf("func2 called.\n");
return 2;
}
int main(void)
{
printf("Hey, this is a test: %d, %d\n", func1(), func2() );
system("pause");
return 0;
}
zhangyanli 2007-12-09
  • 打赏
  • 举报
回复
c采用_cdecl调用方式,参数是从左往右压入堆栈的。

如int a(int p1,int p2)这样的话就是p2先进堆栈,然后是p1
mcmay 2007-12-09
  • 打赏
  • 举报
回复
To ltc_mouse
压栈?push stack?能够说得仔细些吗?谢谢!
mcmay 2007-12-09
  • 打赏
  • 举报
回复
“jf”?什么意思?
ltc_mouse 2007-12-09
  • 打赏
  • 举报
回复
感觉跟参数压栈顺序有关
C语言的参数压栈是从右向左的
yxwsbobo 2007-12-09
  • 打赏
  • 举报
回复
jf

69,382

社区成员

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

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