Compare Preincrimenting and postincrementing. - C++ Operator

C++ examples for Operator:Increment and decrement operators

Description

Compare Preincrimenting and postincrementing.

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    int c;/*from  w ww.jav a2  s.  co  m*/

    // postincrement
    c = 5;
    std::cout << c << std::endl;
    std::cout << c++ << std::endl;
    std::cout << c << std::endl;

    std::cout << std::endl;

    // preincrement
    c = 5;
    std::cout << c << std::endl;
    std::cout << ++c << std::endl;
    std::cout << c << std::endl;

    return 0;
}

Result


Related Tutorials