Question

I m currently preparing a C certification, in the course material relating to pointer NULL, there is this line whch trouble me:

if you want to use the NULL symbol you have to include one of the following header files: stdio.h or stddef.h. The NULL symbol is defined in there.

(Bold are in the source)

Since the or is emphasized, I read it as "never include both". Is it a real norm or is it just one of the (many) flaws in the course material?

Was it helpful?

Solution 3

you can include either one or both. The one to be written first will declare NULL as the first and it wont be declared twice.

OTHER TIPS

It is useless to include both since stdio.h includes stddef.h. But you can include both if you want, since there is a guard to avoid multiple inclusions.

the official place for NULL to be defined is in <stddef.h>. However, on most implementations, you can include <stdio.h> or <string.h> (or quite a few other includes) to pick it up.

It is quite safe to include both, and you should so so if you actually need them (and contrariwise, you shouldn't include <stdio.h> if you don't need it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top