We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Technically, the ternary operator is an if-else statement. Look at what is generated in assembly and you will see that an if-else and a ternary operator generate the same instructions. The ternary operator is just a shorthand form of the if-else and many cases it is better to use the if-else clause. If you use the ternary operator for anything more than a simple test condition, you will not be able to take advantage of the compiler's optimizations.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Conditional Statements
You are viewing a single comment's thread. Return to all comments →
Technically, the ternary operator is an if-else statement. Look at what is generated in assembly and you will see that an if-else and a ternary operator generate the same instructions. The ternary operator is just a shorthand form of the if-else and many cases it is better to use the if-else clause. If you use the ternary operator for anything more than a simple test condition, you will not be able to take advantage of the compiler's optimizations.