C Programming Boolean Expressions

Last modified by Microchip on 2023/11/09 09:06

  • C has no Boolean data type
  • Boolean expressions return integers:
    • 0 if the expression evaluates as FALSE
    • Non-zero if the expression evaluates as TRUE (usually returns 1, but this is not guaranteed)
1 int main(void)
2 {
3    int x = 5, y, z;
4
5    y = (x > 4);     // y = 1 (TRUE)
6    z = (x > 6);     // z = 0 (FALSE)
7    while (1);
8 }