Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Special Assignment Operators ++ and --

Node:Special Assignment Operators ++ --, Next:, Previous:Unary Operator Precedence, Up:Expressions and operators



Special Assignment Operators ++ and --

C has some special operators that can simplify code. The simplest of these are the increment and decrement operators:


++
increment: add one to
--
decrement: subtract one from

You can use these with any integer or floating point variable (or a character in some cases, carefully). They simply add or subtract 1 from a variable. The following three statements are equivalent:

variable = variable + 1;
variable++;
++variable;

So are these three:

variable = variable - 1;
variable--;
--variable;

Notice that the ++ and -- operators can be placed before or after the variable. In the cases above, the two forms work identically, but there is actually a subtle difference. (See Postfix and prefix ++ and -, for more information.)

 
 
  Published under free license. Design by Interspire