C has two special unary operators called increment (++)and decrement (--) operators. These operators increment and decrement value of a variable by 1.
Post-Increment : Value is first processed then incremented. In post increment, whatever the value is, it is first used for computing purpose, and after that, the value is incremented by one.
Pre-Increment : On the contrary, Pre-increment does the increment first, then the computing operations are executed on the incremented value.
Post-Decrement : While using the decrement operator in post form, the value is first used then updated.
Pre-Decrement : With prefix form, the value is first decremented and then used for any computing operations.
The code is a C program that demonstrates the use of increment and decrement operators in C. Here is an explanation of each line of the code:
When you run this code, it will perform increment and decrement operations on variable a and print the results in the console.
It's important to note that pre-increment/decrement operator will increment/decrement the value of the variable first and then use it while post-increment/decrement operator will use the current value of the variable and then increment/decrement it.
//Increment and Decrement Operators #include<stdio.h> int main() { int a=1; printf("\nPre Increment : %d",++a); printf("\nPost Increment : %d",a++); printf("\nA : %d",a);//3 printf("\nPre Decrement : %d",--a); printf("\nPost Decrement : %d",a--); printf("\nA : %d",a); return 0; }To download raw file Click Here
Pre Increment : 2 Post Increment : 2 A : 3 Pre Decrement : 2 Post Decrement : 2 A : 1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions