error: ‘NULL’ undeclared

File null. c.

int main() {
    void *p = NULL;

    return 0;
}

I build 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?

 2
c
Author: Suvitruf - Andrei Apanasik, 2010-11-11

1 answers

NULL is not a keyword. This is the macro definition specified in the standard headers. To use it, you need to connect them.

#include <stddef.h>
 4
Author: Nicolas Chabanovsky, 2010-11-11 16:39:40