ch3-Increment (Auto-increment/decrement operators)
Chapter_3 Exercise_3-5 | Char Exercise_3-6 |
Increment.cpp TCP1, p. 139-140 download
// Shows use of auto-increment and auto-decrement operators
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int i = 0;
int j = 0;
cout << ++i << endl; // Pre-increment
cout << j++ << endl; // Post-increment
cout << --i << endl; // Pre-decrement
cout << j-- << endl; // Post decrement
return 0;
}
/*
g++ Increment.cpp -o Increment
./Increment
1
0
0
1
*/
Note: See also ch2-Arguments_Precedence on Kernighan_and_Ritchie blog, Chapter_2, Sec. 2.12.
Chapter_3 Exercise_3-5 | BACK_TO_TOP | Char Exercise_3-6 |
Comments
Post a Comment