+ 2

C++ compiler question

In the while loop lesson, there's this code: https://code.sololearn.com/cbAZvAc5sP8q/?ref=app I made it a bit more efficient code wise using built in functions and removing some extra things that it had. https://code.sololearn.com/cTo63q2ITBNZ/?ref=app I understand that this case is too simple and the difference may be negligible, but I'm thinking of best practices, more than anything,and in the future. The question is: is the compiler smart enough to optimize and have the same output with both cases? Does it represent an advantage to use, for example x++ instead of x=x+1? Thanks!

21st Oct 2019, 12:01 AM
Juan Vizoso
Juan Vizoso - avatar
5 Respuestas
+ 1
Hi Juan Vizoso. You are right, there is not a big difference. I believe using less lines of code is good, in most cases.
21st Oct 2019, 12:43 AM
Manual
Manual - avatar
+ 1
Thank you guys, I'm just starting, following the beginner lessons and just trying to apply old knowledge and logic to check my understanding...
21st Oct 2019, 2:17 AM
Juan Vizoso
Juan Vizoso - avatar