HP 3000 Manuals

Equality Operators [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Reference Manual

Equality Operators 

The equality operators equal-to (==) and not-equal-to (!=) compare two
operands.

Syntax 

     equality-expression ::=
        relational-expression 
        equality-expression == relational-expression 
        equality-expression != relational-expression 

Description 

The usual arithmetic conversions are performed on the operands if both
have arithmetic type.  Both operands must be arithmetic, or both operands
must be pointers to the same type, or one operand can be a pointer and
the other a null pointer constant or a pointer to void.

Both of the operators == (equal) and != (not equal) yield 1 if the
specified relation is true; otherwise they will yield 0.  The result is
of type int and is not an lvalue.

The == and != operators are analogous to the relational operators except
for their lower precedence.  This means that the expression a<b==c<d is
true if and only if a<b and c<d have the same truth value.

Use caution with the == operator.  It resembles the assignment operator
(=) and is often pronounced the same when programs are read.  Further,
you can use the == operator in expressions syntactically the same as you
would the = operator.  For example, the statements

       if(a==b) return 0;

       if(a=b) return 0;

look very much alike, but are very different.  The first statement says
"if a is equal to b, return a value of zero." The second statement says
"store b into a and if the value stored is nonzero, return a value of
zero."

Examples 

     var1==var2

     var1!=var2



MPE/iX 5.0 Documentation