conditional operator (? :)
syntax: expr1 ? expr2 : expr3
semantic: ? if (expr1) then (expr2) else (expr3)
e.g. x = (y > 1) ? 3 : -3; ?
if y > 1 then x = 3 else x = -3;
main()
{
int x = -O4;
x >> 2;
printf(“%s %d\n”,
(x>=0)?”zero fill”:”sign extent”,x); }
Previous slide
Next slide
Back to first slide
View graphic version