logical operation & pre-increment in c

不羁的心 提交于 2020-01-03 20:16:07

问题


Can any one explain why c still equal 15 after execution

int main(void)
{
    int t,a=5,b=10,c=15;
        t= ++a||++c;
        printf("%d  %d  %d",t,a,c);
}

回答1:


The logical-or operator || is a short-circuit operator. If the left side evaluates to a true boolean value (i.e. not 0), then the right side doesn't execute.

Similarly for the logical-and operator &&, if the left hand side is false (i.e. 0) the right hand side does not execute.



来源:https://stackoverflow.com/questions/31415375/logical-operation-pre-increment-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!