當前位置:編程學習大全網 - 編程軟體 - 在C語言中,int a=5,b; b=++a*--a;b的結果為多少?

在C語言中,int a=5,b; b=++a*--a;b的結果為多少?

答案:25

從下面的代碼可以看出,事實也是++,--都比*優先級別高,實際執行a先自加1,為6,再自減1,為5,在經行乘法運算

測試代碼

int main()

{

int a=5,b; b=++a*--a;

printf("%d\n", b);

}

匯編代碼

main:

leal 4(%esp), %ecx

andl $-16, %esp

pushl -4(%ecx)

pushl %ebp

movl %esp, %ebp

pushl %ecx

subl $36, %esp

movl $5, -12(%ebp)

addl $1, -12(%ebp)

subl $1, -12(%ebp)

movl -12(%ebp), %eax

imull -12(%ebp), %eax

movl %eax, -8(%ebp)

movl -8(%ebp), %eax

movl %eax, 4(%esp)

movl $.LC0, (%esp)

call printf

addl $36, %esp

popl %ecx

popl %ebp

leal -4(%ecx), %esp

ret

.size main, .-main

.ident "GCC: (GNU) 4.1.2 20070502 (Red Hat 4.1.2-12)"

.section .note.GNU-stack,"",@progbits

  • 上一篇:學習Python可以做什麽工作?
  • 下一篇:請問壹下,開發電腦軟件應該怎麽做
  • copyright 2024編程學習大全網