When c like languages say so
$a = 5; $b = 1; $result = $a---$b; echo $a; #=>4 echo $b; #=>1 echo $result; #=>4
public class FunMaths{ public static void main(String[] args) { int result; int a = 5, b = 1; result = a---b; System.out.println(a); System.out.println(b); System.out.println(result); } }
Related posts:
- Making isset Recursive
- Smarty… again
- Damn-it PHP
- Getting Started With PHPUnit
- Finding corrupted images
No tags

tiso · December 15, 2009 at 3:15 am
Operator Precedence and Associativity…
numero (Ondřej Slámečka) · December 15, 2009 at 1:00 am
“When is 4 – 1 = 4? When c like languages say so” http://bit.ly/16ZMUu
Author comment by SeanJA · November 6, 2009 at 1:17 am
The trick here is that it is doing either a prefix or postfix decrement (I guess it would depend on the compiler).
In the case of php and java, it does a postfix decrement, then it ignores the -1 on the end, resulting in {4, 1, 4}
L · October 28, 2009 at 12:11 am
I don’t think I’m getting the joke…have you overloaded the – operator?
triple – operators doesn’t have a valid meaning I’m aware of in C, at least. One is minus, two is decrement.