For one, that's not the kind of "wasted CPU cycles" that you need to worry about. Even if the second condition was checked, that's a cycle or two. Beginners worry about nanoseconds. Experienced programmers worry about microseconds (I used to say they worry about milliseconds, but times are changing). It's called micro-optimisations and is the kind of thing that produces unreadable code without giving any speed advantages, and later on prevents real optimisation because the code is too hard to maintain.
By the definition of the language, in C, C++, Objective-C, Java, C# and probably many other languages, it is well defined that a logical or evaluates the left side first. If the left side is non-zero, then the right side is not evaluated at all. If the left side is zero, only then is the right side touched.
(Compilers are free to actually do what they like as long as it doesn't change the official behaviour which they will do if it is faster).
And in your particular case, after an assignment i = 2 the compiler won't produce code to do any comparison, because it knows the outcome already. i == 2 is true, therefore i == 4 isn't evaluated at all.
void foo(int i) {
same conditional}
. This is exactly the sort of thing that you should completely ignore, as compiler + cpu machinery exist to do that micro-optimisation for you. – Caleth Jun 24 '16 at 10:35