c - Ternary operator vs if else -


this question has answer here:

is ternary operator better if else block in execution time or under different scenerio? have gone through many links didnt satisfied answer.

it isn't better or worse. different, because expression. means can stuff initialize variables it:

int n = some_flag ? 0 : 42; 

or use in other places require expressions:

printf("hello number %d", some_flag ? 0 : 42); 

you can't if-else. performance, in cases 2 interchangeable, extremely unlikely make difference.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -