I recently came across a piece of code
// Program for overcoming division by zero
int a=0; int b=100; int c= a==0 || b/a ; printf("Hello");
// Output: Hello
My theory: According to priority, the / operator has higher priority than ||. So b / a must first execute, and we should get a runtime error.
I guess what happens, although there are:
short circuit operator ||, evaluates LHS a == 0, which is true and therefore does not execute b / a.
Is my theory wrong? I'm sure this is something very simple that I just canβt understand right now
source share