Does C use short circuit evaluation even when arguments are function calls?

前端 未结 3 1683
无人共我
无人共我 2021-01-25 03:40

I know that logical operators do short-circuit checking. That is, if there is a statement like A && B && C, then if A is false,

3条回答
  •  清酒与你
    2021-01-25 04:09

    Yes, the functions are not called if root1->data == root2->data is false.

    Simple check is to do this:

    #include 
    #include 
    
    int main(void)
    {
      write(1, "z", 1);
      if ((1 == 0) && write(1, "a", 1) && write(1, "b", 1))
      {
        write(1, "c", 1);
      }
      write(1, "d", 1);
      return (EXIT_SUCCESS);
    }
    

提交回复
热议问题