Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Does the ternary operator cause you to "question" your programming choices?
@s0LA
It returns a value and allows assignment of the result to a variable. Quite different than if/else. Logically similar, but very handy for conditional assignments. -
int i = a > 1 ? a : 1; // assigns to i
if(a > 1) i = a; else i = 1; // i has to be explicitly assigned
Ternary is much more convenient for short conditional assignments.
Related Rants
Since i know the operator ? my life changed.
joke/meme
operator
else
change
if
life
programming