O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparing Values

Besides operators for assigning and combining values, you also have a set of operators that are used to compare two values and yield a true or false result. Is 1 equal to 2? No (false). Is 100 divided by 1 equal to 1 multiplied by 100? Yes (true). The C programming language provides several symbols to help you test the veracity of an expression:

= =Is equal to?
>Is greater than?
<Is less than?
!=Is not equal to?

The double equals sign == is used to distinguish the expression from an assignment, because you can actually test for the veracity of an assignment within an expression. Like using pre-operators, this is not advised for code clarity but is sometimes useful.

So were you to write code such as the following inside a test condition, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required