Home  >  Article  >  Backend Development  >  In C language, pre-increment (or pre-decrement)

In C language, pre-increment (or pre-decrement)

王林
王林forward
2023-09-07 13:53:111251browse

In C language, pre-increment (or pre-decrement)

The increment operator is used to increase a value by one, while the decrement operator does the opposite of increment. The decrement operator decreases a value by one.

The following is the syntax of the pre-increment operator in C language.

++variable_name;

This is the syntax of the pre-decrement operator in C language.

--variable_name;

Let us take a look at the pre-increment operator and the predecrement operator.

Pre-increment- Before assigning the value to the variable, the value will be incremented by one.

This 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</p><p>",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 will be decremented by one.

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

p>

Example

Real-time demonstration

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

Output

The pre-decremented value : 10
9876

The above is the detailed content of In C language, pre-increment (or pre-decrement). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete