Squirrel Hacker | I have come forward in time from the year 1986 to share this with you

Aug/09

27

When is 4 – 1 = 4?

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);
	}
}
Share and Enjoy:
  • Twitter
  • DZone
  • del.icio.us
  • Slashdot
  • Digg
  • Reddit
  • HackerNews
  • Technorati
  • Google Bookmarks
  • RSS
  • StumbleUpon
  • Yahoo! Buzz
  • LinkedIn
  • Facebook
  • Print
  • PDF
  • email

Related posts:

  1. Making isset Recursive
  2. Smarty… again
  3. Damn-it PHP
  4. Getting Started With PHPUnit
  5. Finding corrupted images

No tags

4 comments

  • tiso · December 15, 2009 at 3:15 am

    Reply

  • 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

    Reply

  • 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}

    Reply

  • 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.

    Reply

Leave a Reply

<<

>>