Arduino IDE: Increment & Decrement Operator

Arduino IDE Increment Decrement Operator
About This Tutorial
This tutorial discusses what are increment operator and decrement operator, two of the many arithmetic operators, their two different structures, and how to use them in Arduino IDE.
Tutorial Info

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Increment Operator

The increment operator is an Arduino arithmetic operator that increments an integer variable by a value of one. This is useful in certain types of loops.

Two possible structures of increment operator:

  • Variable_Name++ : As the ++’ sign is after the variable name, it is a post increment operation. This means that the variable is first used in the statement and incremented after the statement execution.
  • ++Variable_Name : As the ‘++’ sign is before the variable name, it is a pre increment operation. This means that the variable is incremented before execution of the statement.

Example showing the working of the post increment operation:

Increment Operator

Example showing the working of the pre increment operation:

pre increment operation:

Decrement Operator

The decrement operator is used to decrement an integer variable by a value of one.

Two possible structures of increment operator:

  • Variable_Name – – : As the –‘ sign is after the variable name, it is a post decrement operation. This means that the variable is first used in the statement and decremented after the statement execution.
  • – – Variable_Name : As the –‘ sign is before the variable name, it is a pre decrement operation. This means that the variable is decremented before execution of the statement.

Example of post decrement operation

post decrement operation:

Example of pre decrement operation:

pre decrement operation:

 

Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
How to interface DC motor with Arduino IDE
This tutorial discusses what are DC motors, how to control them, and how to interface them with Arduino IDE using motor control units in evive with the help of an Arduino IDE sketch.
All articles loaded
No more articles to load
Featured Projects
Space-Battle-Game on Scratch
Space Battle

This project will show you how to make a cool space battle game on your own in PictoBlox (Scratch-based programming) and play using your Smartphone!

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart