C++ Program using Increment Operator

The values of variables can be incremented using ++ operator. And the value can be decremented using — operator. You can either pre-increment or post-increment the values.

using namespace std;
int main(){
	int a = 30;
	int b;
	cout<<"a = "<<a<<" b = "<<b<<endl;
	b = a++;
	cout<<"a = "<<a<<" b = "<<b<<endl;
	a = 30;
	b = ++a;
	cout<<"a = "<<a<<" b = "<<b<<endl;
	return 0;
output of above program. program using increment operator
output of above program.

You should use decrement operator — to reduce the value.

Leave a Reply