Thread: Boolean Algebra
View Single Post
Dec 13th, 2004
0

Re: Boolean Algebra

Correction:

(statment) ? a : b

if the statement is true it takes a
if the statement is false it takes b

however because you cant use block statements like the if function it is only useful to save coding space if the only action taken is to give the variable a value. for example

if(x == 0)
{
MessageBox(NULL, "X = 0", "Message", MB_ICONINFORMATION | MB_OK);
SomeOtherFunction();
...
}
else
{
....
}

cannot be simplified but...

the abs function (always +) which is:

if(a > 0)
return a;
else
return -a;

can be defined as

#define abs(a) (a > 0) ? a : -a;
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004