Binary Operations

 

//This program will demonstrate binary operations
#include <iostream.h>

main()

{
int x = 3, y = 4, r = 2, w = 1, k =5;

cout << x << '\n';
x++; //incrementing x by 1;
cout << x << '\n'; 

/* below means the same r = (y + 1) + 3;
y is incremented after the assingment.*/
r = y++ + 3; 
cout << r << "***" << y << '\n';

/* below means the same w = (y + 1) + 3;
y is incremented before the assignment.*/
w = ++y + 4; 
cout << r << "***" << y << '\n';

r = --x + 7;
cout << r << "***" << x << '\n';
r = w-- + 7;
cout << r << "***" << w << '\n';

k += 3; // means k = k + 3;
cout << k << "***\n";

k -= 5 + x; // means k = k - (5 + x);
cout << k << "ZZZ\n";

r /= 3; // means r = r / (3);
cout << r << "***\n";

w += ++k + 3;
cout << w << "**" << k << '\n';

x -= r-- + 3;
cout << x << "**" << x << '\n';

return 0;
}

/*
3
4
7***5
7***6
10***3
17***9
8***
0ZZZ
5***
13**1
-5**-5
*/