Why == works in an if statement?

Hi,
I think what you are curious about is the reason why the simple '=' is not used while checking conditions.

The '=' sign is used as the assignment operator and it assigns the value to its right to the variable to its right. similarly you use '==' to compare values. The reason the same operator is NOT used to do both the comparison and assignment is because it would be quite ambiguous.

For example if you write a = 25 the compiler assigns the value of 25 to the variable a but if you use a == 25 the compiler compares the two values and returns a true if the value of a is 25 else it returns a false.

Also, << and >> are used in bit shift operations and hence are not used to make comparisons.