/* 目录: 一 代码测试 二 汇编原理 三 仿写函数 */
一 代码测试
int main() { int i = 3; int k = 0; int m = 0; k = ++i; printf("k = %d i = %d ", k, i); m = i++; printf("m = %d i = %d", m, i); return 0; } /* // result k = 4 i = 4 m = 4 i = 5 */
二 汇编原理
k = ++i; 00044E63 mov eax,dword ptr [i] 00044E66 add eax,1 00044E69 mov dword ptr [i],eax 00044E6C mov ecx,dword ptr [i] 00044E6F mov dword ptr [k],ecx m = i++; 00044E87 mov eax,dword ptr [i] 00044E8A mov dword ptr [m],eax 00044E8D mov ecx,dword ptr [i] 00044E90 add ecx,1 00044E93 mov dword ptr [i],ecx
三 仿写函数
#include "stdafx.h" int FirstPlus(int *pInt) { *pInt = *pInt + 1; return *pInt; } int AfterPlus(int *pInt) { int nReturn = 0; nReturn = *pInt; *pInt = *pInt + 1; return nReturn; } int main() { int i = 3; int k = 0; int m = 0; printf("k = %d i = %d ", k, i); k = FirstPlus(&i); printf("k = %d i = %d ", k, i); printf("m = %d i = %d ", m, i); m = AfterPlus(&i); printf("m = %d i = %d", m, i); return 0; } /* // result k = 0 i = 3 k = 4 i = 4 m = 0 i = 4 m = 4 i = 5 */