Count forward several years using prefix and postfix increment operators. - C++ Operator

C++ examples for Operator:Increment and decrement operators

Description

Count forward several years using prefix and postfix increment operators.

Demo Code

#include <iostream> 
 
int main() //from w  w  w .j  a  v  a 2s. c o  m
{ 
    int year = 2018; 
    std::cout << "The year " << ++year << " passes.\n"; 
    std::cout << "The year " << ++year << " passes.\n"; 
    std::cout << "The year " << ++year << " passes.\n"; 
 
    std::cout << "\nIt is now " << year << "."; 
    std::cout << " Have the Chicago Cubs won the World Series yet?\n"; 
 
    std::cout << "\nThe year " << year++ << " passes.\n"; 
    std::cout << "The year " << year++ << " passes.\n"; 
    std::cout << "The year " << year++ << " passes.\n"; 
 
    std::cout << "\nSurely the Cubs have won the Series by now.\n"; 
    return 0; 
}

Result


Related Tutorials