i isn't 0, so the first part of the logical AND succeeds. i is then incremented. Next j isn't 0, so the second part of the logical AND succeeds. j is incremented. The OR part of the test isn't performed due to short circuiting and m is set to a true value.
You can change how things work by making either i or j zero initially such that the AND part of the test fails. This will force the OR part of the condition to be executed. Changing i to zero will result in an output of "2 1" because i is now incremented twice.
That's why I forgot that it's undefined behavior. Because it isn't. ;)
How is it undefined.
As Walt said, it's not. At first glance one might make that mistake though, because there's a rule about modifying a single object more than once between sequence points being undefined. However, the || and && operators introduce a sequence point, so the statement is well defined. I myself gave it a double take to make sure everything was kosher before answering. ;)
Why are || and && sequence points? Rhetorical, no need to explain - I can see why they could be just not why they should be...
Actually, that's a good question because it's not immediately obvious.
I'm sure you guessed that it's because of the short circuiting behavior. The operands are expected to be executed in a specific order, and a sequence point is required to enforce that order. If there weren't a sequence point for &&, for example, then the right hand expression couldn't expect the side effects of the left hand expression to have completed.
Is enforcing full completion of the expression necessary to make short circuiting work in all cases? To be honest, I'm having trouble thinking of an example that's practical in the real world, but that doesn't mean there aren't any.;)
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.