This is a Cpp program to test increment and decrement operators. Increment operator increases the value by 1. Decrement operator decreases by 1. There are two types of increment and decrement operators ( pre and post) ++a preincremeent (first increments the value for processing) a++ postincrement ( first time same value of a is used , then for after use it increments by 1) --a preincrement (first decrements the value for processing) a-- postincrement( first time same value of a is used , then for after use it decrements by 1) |
PROGRAM :
#include <iostream> using namespace std; int main() { int num1,num2,temp_num; cout << "Enter 1st number : \t" ; cin >> num1; cout << "\n Enter 2nd number : \t"; cin >> num2; cout << "\nThe numbers before swapping : \t" << num1 << "\t"<< num2 << endl; temp_num=num1; num1=num2; num2=temp_num; cout << " \nThe numbers after swapping : \t" << num1 << "\t"<< num2 << endl; return 0; }
OUTPUT :
Cpp Programming - Increment and Decrement Operators |