- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
#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
#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
Advertisements