Examples of Conditional Operators
int main(void)
{
int x=0, y=10, w=20, z, T=1, F=0;
z = (x == 0); /* logical operator; result --> 0 or 1 */
z = (x = 0); /* assignment operator; result --> */
z = (x == 1);
z = (x = 15);
z = (x != 2);
z = (x < 10);
z = (x <= 50);
z = ((x=y) < 10); /*performs assignment, compares with 10*/
z = (x==5 && y<15);
z = (x==0 && y>5 && w==10);
z = (x==0 || y>5 && w==20);
z = (T && T && F && x && x); /*** ==> F; ***/
z = (F || T || x || x); /*** ==> T; ***/
/*** for && and ||, order is specified,
stops when result is known, ***/
/*** value of x doesn't matter ***/
return 0;
}
|