1. ## help: simple problem

hi,

just started c prog for college. useless at it. need help finding out what this comes to.its for exam.

three parts:

a =3, b=2, c=4,

what values of following if legal:

b<a<c

a*b%c+3

--b*c+a

need help especially with --b;

also what does <<a or >>a mean

2. Originally Posted by screamer903
need help especially with --b;
-- is unary decrement operator which evaluates to
Code:
```--b;//same as
b = b -1;```
So, it'll decrement the value of b first and then only will it return the final value of b.
Originally Posted by screamer903
also what does <<a or >>a mean
Have a look at the shift operators explanation in the FAQs then if there is something specific you're unclear about post back.

3. >b<a<c
Legal, but it doesn't do what you may expect. At first glance one might expect this to say "true if b is less than a and a is less than c", but in reality it compares the boolean result of b < a (0 or 1) to c. b is 2 and a is 3, so b < a is true. c is 4, so 1 < 4 is also true.

>a*b%c+3
This is an easy one, all operations go from left to right. So it's:
Code:
`( ( 3 * 2 ) % 4 ) + 3`

4. >>the boolean result of b < a (0 or 1)
I was always under the impression that true was represented as anything nonzero, and that it wasn't guaranteed to be 1. That would mean that the statement is totally unpredictable, but I probably missed something somewhere.

5. Originally Posted by XSquared
I was always under the impression that true was represented as anything nonzero
"On input":
http://www.eskimo.com/~scs/C-faq/q9.2.html

6. >I was always under the impression that true was represented as anything nonzero
Correct. True is non-zero and false is zero. However, boolean expressions are well defined and always evaluate to either 0 or 1.

7. It makes for neat little tricks like replacing:
Code:
```if(a > b)
c++;```
with:
Code:
`c += a > b;`

8. That's not nearly as practical as my brilliant binary search tree trick:
Code:
```struct node {
T data;
};

struct node *insert ( struct node *tree, T data )
{
if ( tree == NULL ) {
tree = make_node ( data );
} else {
int dir = data > tree->data;
}

return tree;
}```
It gets better and better as the symmetric cases get longer and longer.

9. ## Well I Do Have The Explanation

a*b%c+3

in this apply the BOMDAS rule
that is bracket
of
multiply
divide
substract

--b*c+a
--b will decrease the value od b by one unit
the remaining will Follow bomdas rule

>>a and <<a are the right shift and left shift operators which will shift the binary blase either right or left

for example,
10 = 1010(in binart system)
>> 10= 0101 =5 (here, the binary digits got shifted to a place right)