-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPre_n_PostOperators.cpp
More file actions
46 lines (28 loc) · 1.07 KB
/
Pre_n_PostOperators.cpp
File metadata and controls
46 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Elaborates more on Post and Pre decrement/increment operators
*/
#include <iostream>
using namespace std;
int main()
{
int mark = 76; // declare and initialize variable of type int
cout << mark << endl; // 76
mark++; // increase by 1 (post-increment)
cout << mark << endl; // 77
++mark; // increase by 1 (pre-increment)
cout << mark << endl; // 78
mark = mark + 1; // also increase by 1 (or mark += 1)
cout << mark << endl; // 79
mark--; // decrease by 1 (post-decrement)
cout << mark << endl; // 78
--mark; // decrease by 1 (pre-decrement)
cout << mark << endl; // 77
mark = mark - 1; // also decrease by 1 (or mark -= 1)
cout << mark << endl; // 76
cout << "\nExplanation -- \n";
cout <<"mark++ = "<< mark++ << endl; // save mark(76); increment mark(77); print old mark(76);
cout << "\nmark now = " << mark<<endl;
cout << "++mark = " << ++mark << endl; // increment mark(78); print current mark(78);
system("pause"); // put the processing for slep until a key is pressed
return 0;
}