what is this means?

1
2
width = ((w >=0) ? w : 0);
length = ((l>=0) ? l:0);

can anyone translate to eng to me? i don't get what does that code means? the side note of the code saids "traps invalid values" the code belong in a calculating rectangle area/perimeter code.
width = ((w >=0) ? w : 0);

This is equivalent to:

1
2
if(w >= 0) width = w;
else width = 0;

It's called an arithmetic if.
Last edited on
closed account (zb0S216C)
It's called a Ternary Operator.
http://en.wikipedia.org/wiki/Ternary_operation
Last edited on
Topic archived. No new replies allowed.