Confusion with post increment and logical operator?

前端 未结 3 1454
误落风尘
误落风尘 2021-01-17 05:01
    #include 
    #include 

    main()
    {
         int i=-1, j=-1, k=0, l=2,m;
         m = i++&&j++&&k++||l++;
           


        
3条回答
  •  清歌不尽
    2021-01-17 06:03

    All that really matters here is the ||. Since l++ evaluates to the boolean 1 (true), the entire statement is true. So m is 1, and the rest are just their original values plus one for the post increment after they are evaluated.

    You're evaluating the boolean expression:

    ((-1 && -1) && 0) || 2
    

    As an aside, your definition of main should be:

    int main(void)
    

提交回复
热议问题