operator-precedence

Why does this C program print weird characters in output?

Dear all, I've the following program: #include <stdio.h> int main() { int ch; while( ch = getchar() != '\n') { printf("Read %c\n",ch); } return 0; } No matter what I enter I get: Read Why is this happening and what is that weird char that I see? Stackoverflow is not printing th...

Shortcircuiting: OrElse combined with Or

If I have the following ... a OrElse b ... and a is True then clearly b is never evaluated. But if I add an Or, then what? a OrElse b Or c Does/should c get evaluated? And what if I put in some brackets? Apologies if this is basic. Of course I can test for the answer myself but I can't find this question answered here or elsewher...

Bitwise operator predence

A gotcha I've run into a few times in C-like languages is this: original | included & ~excluded // BAD Due to precedence, this parses as: original | (included & ~excluded) // '~excluded' has no effect Does anyone know what was behind the original design decision of three separate precedence levels for bitwise operators? More im...

PHP: if(!$one == $two) doesn't work always?

Yes, this is just a question i would like to get an answer on. I experienced it a couple of times, where this: if(!$one == $two){ echo "Not the same"; }else{ echo "The same"; } Will not work, and if($one == $two){ echo "The same"; }else{ echo "Not the same"; } will work. Why doesn't it work sometimes? I always need to recode like ...

AND, OR output wrong result

Suppose I use 2 AND and one OR to retrieve a result, first test with input text value on name, I could get correct result but when I change $getc to any value other than empty string, the result does not change, it only query name value. What is wrong? $query1 = "SELECT * FROM $tableName WHERE name LIKE '%$asd%' OR descriptions LIKE ...

Precedence of operators in SQL*Plus

How is A - B U B - A parsed in SQL*Plus? Is it parsed as (A - B) U (B - A) or as A - (B U B) - A ? I could find this page using Google, but it doesn't say which has higher precedence, U or -. ...

What is the right precedence of the math expression

What is the correct sequence of the math operations in this expression in Java: a + b * c / ( d - e ) 1. 4 1 3 2 2. 4 2 3 1 I understand that result is the same in both answers. But I would like to fully understand the java compiler logic. What is executed first in this example - multiplication or the expr...