// Justin C. Miller
// University of Wisconsin Oshkosh
// Made for: http://www.geocities.com/neonprimetime.geo/index.html
// Date: 2001
// Borland Builder 4.0
// ++ , --
#include
#include
// ++ adds 1 to a variable
// -- subtracts 1 to a variable
int main()
{
int a = 3 ;
cout << "a = " << a << endl ;
// ++ before a variable means that it will
// be incremented by 1 then printed out
// thus the next line prints out a, then it increments it by 1
// so the next line prints out a 4
cout << "++a is already = " << ++a << endl ;
// ++ after the variable means that it will
// be printed out first, then incremented
// so the following line still prints out a 4 (not 5)
cout << "a++ is still = " << a++ << endl ;
// but the next line prints out a 5 because the above ++ now took place
cout << "but now a is = " << a << endl ;
// the same things can be done with -- (substracting 1)
// the ++ and -- are most commonly used in for loops
// like the 2 below
// this prints 1 to 5
for(int i = 1 ; i <= 5 ; i++)
cout << i << " " ;
cout << endl ;
// this prints 5 to 1
for(int j = 5 ; j >= 1 ; j--)
cout << j << " " ;
getch() ;
return 0 ;
}
// OUTPUT
//
// a = 3
// ++a is already = 4
// a++ is still = 4
// but now a is = 5
// 1 2 3 4 5
// 5 4 3 2 1
               (
geocities.com/neonprimetime.geo/cpp)                   (
geocities.com/neonprimetime.geo)