Pre-increment (or pre-decrement) in C


Increment operators are used to increase the value by one while decrement works opposite increment. Decrement operator decreases the value by one.

Here is the syntax of pre-increment operator in C language,

++variable_name;

Here is the syntax of pre-decrement operator in C language,

--variable_name;

Let us see the difference between pre-increment and pre-decrement operator.

Pre-increment − Before assigning the value to the variable, the value is incremented by one.

Here is an example of pre-increment in C language,

Example

 Live Demo

#include <stdio.h>
int main() {
   int i = 5;
   printf("The pre-incremented value : %d
",i);    while(++i < 10 )    printf("%d\t",i);    return 0; }

Output

The pre-incremented value : 5
6789

Pre-decrement − Before assigning the value to the variable, the value is decremented by one.

Here is an example of pre-decrement in C language,

Example

 Live Demo

#include <stdio.h>
int main() {
int i = 10;
   printf("The pre-decremented value : %d
",i);    while(--i > 5 )    printf("%d\t",i);    return 0; }

Output

The pre-decremented value : 10
9876

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 24-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements