Pre-decrement and Post-decrement operator in C/C++ Programming Language
In this article we will briefly discuss about what is pre decrement operator and post decrement operator in C/C++ programming language.
Pre-decrement operator:
A pre-decrement operator is used to decrement the value of a variable before using it in a expression. In the Pre-decrement, value is first decremented and then used inside the expression.
Eg: b = --a;
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter the first number\n");
scanf("%d",&a);
b=--a;
printf("%d",a);
printf("\n%d",b);
getch();
}
Post-decrement operator:
A post-decrement operator is used to decrement the value of variable after executing expression. In the Post-decrement, value is first used in a expression and then decremented.
Eg: b=a--;
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter the first number\n");
scanf("%d",&a);
b=a--;
printf("%d",a);
printf("\n%d",b);
getch();
}

0 Comments