您的位置:首页 > 其它

i++和++i的区别

2016-06-29 16:48 183 查看
       a=i++;相当于 a=i;i=i+1;

       a=i--; 相当于 a=i;i=i--;

       

      a=++i;相当于 i=i+1;a=i;

       a=--i; 相当于 i=i--;a=i;

举个栗子:

#include<stdio.h>
main(){
int a;
int i=5;
a=i++;
printf("%d,%d\n",a,i);
a=i--;
printf("%d,%d\n",a,i);
a=++i;
printf("%d,%d\n",a,i);
a=--i;
printf("%d,%d\n",a,i);
return 0;
}

结果是:5,6

                6,5

                6,6

                5,5

在数组中也是一样:

MenuIndex = MenuIndex_LastLvl[--MenuLevel];//1

MenuIndex_LastLvl[MenuLevel++] = MenuIndex;//2

    1中先执行--;再赋值;
    2中先赋值;在执行++;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ++ --