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/SYNTAX/logical.html | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 reference/C/SYNTAX/logical.html (limited to 'reference/C/SYNTAX/logical.html') diff --git a/reference/C/SYNTAX/logical.html b/reference/C/SYNTAX/logical.html new file mode 100644 index 0000000..54cb246 --- /dev/null +++ b/reference/C/SYNTAX/logical.html @@ -0,0 +1,102 @@ +Logical AND OR and NOT + + + + +
+
+

Logical AND OR and NOT

+
+
+ + +
+ +

Logical AND

+In simple terms, && is true (1) if both sides of the expression returns NOT 0. +

+For Example: +

+	/* These all return TRUE (1) */
+
+	if (4 && 5) return();
+
+	i=3;
+	j=2;
+	return( i && j);
+
+The expression is evaluated 'Left to Right' If any part of the expression +returns ZERO - The evaluation ends. +

+THIS CAN CAUSE SERIOUS PROBLEMS. +

+For example: +

+	k=0;
+	i=3;
+	j=2;
+	if ( i-i && j++) k=1
+
+The left side (i-i) resolves to 0, so j is not incremented +and k is not changed. +
+
+

Logical OR

+OR also evaluates 'Left to Right' and will stop when an expression +returns true.

+SO WATCH YOUR BACK.... +

+

+	k=0;
+	i=3;
+	j=2;
+	if ( i+i && j++) k=1
+
+What are j and k going to be when this code is executed????? + +
+
+

Logical NOT

+ +NOT reverses the logical state of its +
operand. If the operand is 0, 1 is +returned, else 0 is returned. + +
+	!4	/* Returns 0	*/
+	!-4	/* Returns 0	*/
+	!1	/* Returns 0	*/
+	!0	/* Returns 1	*/
+
+ + +

+ +


+

+

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

+


+
Martin Leslie +

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