prefix and post-fix using decrement operator C++

Feb 5, 2017 at 7:42pm
Personal contribution.

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
#include <iostream>
using namespace std;

// Program to explain prefix and post-fix using decrementation.

void functionOne (){
	int a = 50;
	int b = 60;
	int c = 0;

	c = (a--) + (b--);
	cout << "c: " << c << endl;
	cout << "a: " << a << endl;
	cout << "b: " << b << endl;
	cout << endl << endl;

}

void functionTwo (){
	int a = 50;
	int b = 60;
	int c = 0;

	c = (--a) + (--b);
	cout << "c: " << c << endl;
	cout << "a: " << a << endl;
	cout << "b: " << b << endl;
}

int main(){
	functionOne();
        functionTwo();
	return 0;
}


c: 110
a: 49
b: 59


c: 108
a: 49
b: 59
Last edited on Feb 5, 2017 at 7:49pm
Topic archived. No new replies allowed.