1

Is both NULL and false are equivalent to 0 (int) in C ? For example both lines below return the same value?

return NULL;

return false;
Barmar
  • 741,623
  • 53
  • 500
  • 612
may
  • 29
  • 4
  • 2
    When `NULL` and `false` are compared with a literal `0`, they will compare equal. But the types of `NULL`, `false` and `0` are different. So operations other than a comparison may result in warnings about type mismatches. – user3386109 Nov 30 '20 at 19:40
  • Because the value of false is int whereas NULL is actually a pointer so it just contain an adress? – may Nov 30 '20 at 19:53
  • It gets confusing because the types have a long and convoluted history. Even today, the types depend on the implementation. By convention, `NULL` is a pointer (typically a pointer to void), `false` is a boolean (which has a whole convoluted history unto itself), and `0` is an `int` (unless otherwise specified using a suffix, e.g. `0ULL`). In short, the whole thing is just a big mess. – user3386109 Nov 30 '20 at 20:02

0 Answers0