c - Ternary operator vs if else -
this question has answer here:
- if/else vs ternary operator 4 answers
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
Post a Comment