Home / Programs / Example of Increment and Decrement operator in cprogramming langauage
Programming Example

Example of Increment and Decrement operator in cprogramming langauage

👁 987 Views
💻 Practical Program
📘 Step by Step Learning
Imagine you have operation as below num = num + 1; you can simply this syntax use ++. num++; using the same approach for this case num = num - 1; you can use — syntax. num--; Now how to implement them in code. Let’s write this code.

Program Code

#include <stdio.h>
int main() {
	int a = 10;
	a++;
	printf("%d \n",a);
	a++;
	printf("%d \n",a);
	++a;
	printf("%d \n",a);
	a--;
	printf("%d \n",a);
	a--;
	printf("%d \n",a);
	--a;
	printf("%d \n",a);
	return 0;
}

Output

11
12
13
12
11
10
Press any key to continue . . .

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.