[Solved] Confusing and unexpected behaviour of “if” statement in C [closed]


You didn’t copy the program correctly. This is the real program that reproduces the bug:

#include <stdio.h>

#define TRUE  1
#define FALSE 0

int function_returning_false() {return FALSE;}

int main() {
  if (function_returning_false) {         // note, no ()
    printf("function returned true\n");
  }
}

So, it’s not calling the function – it is passing the function as an argument to if and in boolean context, a function will always be true.

solved Confusing and unexpected behaviour of “if” statement in C [closed]