C++中++i与i++

#include "stdafx.h"
#include "string"
#include "iostream"
#include "vector"
#include "sstream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    //前置版本,将运算对象+1,然后将改变后的对象作为求值结果
    int j=0;
    int i=10;
    j=++i;
    cout<<"i="<<i<<endl; //i=11
    cout<<"j="<<j<<endl; //j=11

    //后置版本,将运算对象+1,但是求值结果是运算对象改变之前结果的的副本
    int j1=0;
    int i1=10;
    j1=i1++;
    cout<<"i1="<<i1<<endl; //i=11
    cout<<"j1="<<j1; //j=10

    getchar();
    return 0;
}

原文链接: https://www.cnblogs.com/wicrecend/p/4530076.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/216691

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 上午9:30
下一篇 2023年2月13日 上午9:31

相关推荐