0

Why post-decrements operator in the following C code is not working as desired? (to have the value of 7). Knowing that it is not an undefined behaviour.

#include<stdio.h>
    int main()
    {
    int a = 8, r;
    r = (a==8) || (a--);
    printf("a = %d\n", a);
    return 0;
    }
Kasra
  • 891
  • 1
  • 10
  • 17

1 Answers1

2

In the expression (a==8) || (a--); since (a==8) is already true hence rest of the OR condition is not evaluated.

Sandy
  • 895
  • 6
  • 17