Faster Statement Execute

Which one will execute faster if(flag==0) or if (0==flag) and why?

Questions by unconquerable

Showing Answers 1 - 9 of 9 Answers

monigoyal

  • Nov 8th, 2010
 

Hi,

When I execute both the condition (flag==0)executed first then(0==flag).I really dont know the reason but I think it must be due to boolean value.

  Was this answer useful?  Yes

Both gcc and Visual Studio generated the exact same machine code for both forms (as well as for !flag), so neither version would be faster than the other for platforms using those compilers.  Frankly, I'd be surprised if any compiler generated different code for the two forms. 

  Was this answer useful?  Yes

ridercoder

  • Dec 25th, 2010
 

It all depends on what assembly code the compiler generates. Essentially, do "0 == flag" and "flag == 0" compile down to the same code, or not?

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions