From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONCEPT/inc_dec.html | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 reference/C/CONCEPT/inc_dec.html (limited to 'reference/C/CONCEPT/inc_dec.html') diff --git a/reference/C/CONCEPT/inc_dec.html b/reference/C/CONCEPT/inc_dec.html new file mode 100644 index 0000000..dd8216b --- /dev/null +++ b/reference/C/CONCEPT/inc_dec.html @@ -0,0 +1,84 @@ +Increment and decrement. + +
+
+

Increment and decrement.

+
+
+ +The traditional method of incrementing numbers is by coding something like: +
+	a = a + 1;
+
+Within C, this syntax is valid but you can also use the ++ operator to perform +the same function. +
+	a++;
+
+will also add 1 to the value of a. +By using a simular syntax you can also decrement a variable as shown below. +
+	a--;
+
+These operators can be placed as a prefix or post fix as below: +
+	a++;		++a;
+
+When used on their own (as above) the prefix and postfix have the same effect +BUT within an expression there is a subtle difference....

+ +

    +
  1. Prefix notation will increment the variable BEFORE the +expression is evaluated. +
  2. Postfix notation will increment AFTER the expression evaluation. +
+ +Here is an example: +
+	main()				main()
+	{				{
+	  int a=1;			  int a=1;
+	  printf(" a is %d", ++a);	  printf(" a is %d", a++);
+        }				}
+
+
+ +In both examples, the final value of a will be 2. BUT the first +example will print 2 and the second will print 1. + +
+ + Example program.
+ + +Other operators.
+ + +Operator precedence table. +
+

+

+ + + + +
+Top + +Master Index + +Keywords + +Functions +
+
+

+ +


+
Martin Leslie + +
-- cgit v1.2.3-54-g00ecf