File null.c.

int main() { void *p = NULL; return 0; } 

I collect using gcc.

 $ gcc null.c 

I get an error.

null.c: In function 'main':
null.c: 2: error: 'NULL' undeclared (first use in this function)

What's wrong?

    1 answer 1

    NULL is not a keyword. This is a macro defined in standard headers. To use it you need to connect them.

     #include <stddef.h> 
    • Better yet, honestly write zero and not suffer :) - Qwertiy
    • Bearded uncles say it is a bad form. - woto