=="&的返回QUOT值;操作者用C [英] Return value of "==" operator in C

查看:139
本文介绍了=="&的返回QUOT值;操作者用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以假设,在C中,==运营商将始终为1,如果两个值相等,也可以计算为其他的真值?

 结构SS {
    INT ID;
};的OS {
    INT SID;
    INT状态;
};诠释计数(结构SS * S,诠释状态)
{
    INT NUM = 0;
    在哈希表//的foreach O(类型OS *)
        NUM + =邻>国家==状态和放大器;&安培; (?的邻> SID == S-和SEQ ID:1);    返回NUM;
}

所以邻> SID == S-> ID 总是会返回1或0,或者它可以返回其他值


解决方案

  

我可以假设,在C中,==运营商将始终为1,如果两个值相等,也可以计算为其他的真值?


是的,也是如此 = &GT; <!/ code> &LT; &GT; = &LT; = 所有的关系运算符

C11(ISO / IEC 9899:201X)§6.5.8的关系运算符


  

每个运营商和LT的; (小于),>(大于),LT =(小于或等于),和> =
  (大于或等于)应得到1-如果指定的关系为真和0,如果它是
  false.107)结果的类型为int。


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?

解决方案

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.

这篇关于==&QUOT;&的返回QUOT值;操作者用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆