Tuesday, September 01, 2009

Lesson of the Day - Bitwise Operator (C Programming)


If use in the program, it goes like this:

#include
main()
{
int x,y;
printf("Enter the value of x:");
scanf("%d",&x);
y=x>9 ? 100:200;
printf("The value of y is %d.",y);
getch();
}

The output in the screen after being run is:

Enter the value of x: 10
The value of y is 200.

Explanation:

Because when the expression is false the value of y is the 200. And if the expression is true, the value of y is 100. Therefore, n:d (100:200) n is display when true and d is display when false.



Labels:

0 Comments:

Post a Comment

<< Home