Why 1 && 2 == 2
blog.chewxy.com
Why 1 && 2 == 2
1–10 of 58 posts
Re: Why 1 && 2 == 2
#2 (cout
...which is not an error, since the result of operatorDisambiguating the expression with parentheses should output 1 in every case.Re: Why 1 && 2 == 2
#3In C++, (cout ...which is not an error, since the result of operator Disambiguating the expression with parentheses should output 1 in every case.
Thanks
Re: Why 1 && 2 == 2
#4 echo 2 && 1; // 1
echo 1 && 2; // 1
echo 2 || 1; // 1
echo 1 || 2; // 1
echo 2 ?: 1; // 2
In php ?: is javascript's || Unfortunately there is no && that works correctly.Re: Why 1 && 2 == 2
#5EDIT: Oh, missed the errata.
Re: Why 1 && 2 == 2
#6Thank god he didn't try php. echo 2 && 1; // 1 echo 1 && 2; // 1 echo 2 || 1; // 1 echo 1 || 2; // 1 echo 2 ?: 1; // 2 In php ?: is javascript's || Unfortunately there is no && that works correctly.
$ php -r 'var_dump(1 && 2);'
bool(true)Re: Why 1 && 2 == 2
#7Re: Why 1 && 2 == 2
#8How did he get an expression that shouldn't involve any memory references to segfault?
Re: Why 1 && 2 == 2
#9How did he get an expression that shouldn't involve any memory references to segfault?
I suck at C?
int *a = 1, *b = 2;
printf("%d\n", *a && *b);
Either that or he used `%s` as a format specifier. That seems more probable.Edit: Or, as I just realised the people below me meant,
printf(a && b);Re: Why 1 && 2 == 2
#10Earlier quoted context omitted.
I suck at C?
He probably thought pointers are the only kind of variables and that he needed to dereference them. I imagine something like int *a = 1, *b = 2; printf("%d\n", *a && *b); Either that or he used `%s` as a format specifier. That seems more probable. Edit: Or, as I just realised the people below me meant, printf(a && b);