Search code examples
c++performanceconditional-operator

Ternary operator ?: vs if...else


In C++, is the ?: operator faster than if()...else statements? Are there any differences between them in compiled code?


Solution

  • Depends on your compiler, but on any modern compiler there is generally no difference. It's something you shouldn't worry about. Concentrate on the maintainability of your code.