Hello guys,
while I'm studing some c codes i found this page:
http://www.nicksays.co.uk/2009/05/awesome-c-exam-question/
and this code:
#include <stdio.h>
int func (int a, int b) {
static int c = 1;
return a + b * (c *= -1);}
int main () {
int a = 2, b = 3;
int c = func(a, b);
a *= a++;
b *= ++b;
printf("%d %d %d %d\n", a, b, c, func(a, b));}
thats prints: 5 16 -1 21
then I made a similar php script:
<?php
function func ($a, $b) {
static $c =1;
return $a + $b * ($c *= -1);
}
function main() {
$a = 2;
$b = 3;
$c = func($a, $b);
$a *= $a++;
$b *= ++$b;
printf("%d %d %d %d\n", $a, $b, $c, func($a, $b));
}
main();
?>
and for my surprise its prints: 6 16 -1 22
so, somebody know and can explain me wtf happened?
Thanks!
Adir Kuhn