Can I assume that in C, the "==" operator will always evaluate to 1 if the two values are equal or it can evaluate to other "true" values?
struct ss { int id; }; struct os { int sid; int state; }; int count(struct ss *s, int state) { int num = 0; // foreach o (of type os*) in a hash table num += o->state == state && (s ? o->sid == s->id : 1); return num; }
So o->sid == s->id
will return always 1 or 0, or it can return other values?
This means that each bit can be one of 4 values: 0,1,x,z. With the "case equality" operator, === , x's are compared, and the result is 1. With == , the result of the comparison is not 0, as you stated; rather, the result is x, according to the IEEE Std (1800-2009), section 11.4.
=== is not an operator in C. It is used in other languages, such as PHP. In PHP, === checks for value and type. – Sarwar Erfan.
The assignment operators in C and C++ return the value of the variable being assigned to, i.e., their left operand. In your example of a = b , the value of this entire expression is the value that is assigned to a (which is the value of b converted into the type of a ).
In the C Programming Language, the strcmp function returns a negative, zero, or positive integer depending on whether the object pointed to by s1 is less than, equal to, or greater than the object pointed to by s2.
Can I assume that in C, the "==" operator will always evaluate to 1 if the two values are equal or it can evaluate to other "true" values?
Yes, and so does !=
>
<
>=
<=
all the relational operator.
C11(ISO/IEC 9899:201x) §6.5.8 Relational operators
Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false.107) The result has type int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With