Home > Backend Development > C++ > body text

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

王林
Release: 2023-09-07 13:53:11
forward
1269 people have browsed it

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;
Copy after login

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

--variable_name;
Copy after login

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;
}
Copy after login

Output

The pre-incremented value : 5
6789
Copy after login

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;
}
Copy after login

Output

The pre-decremented value : 10
9876
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template