0

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?

2
  • 2
    Maybe they wanted to emphasize that it is an or and no xor ;) Feb 24, 2014 at 11:39
  • 1
    By convention, OR is inclusive, so you should read "A or B" as "either A or B, or both A and B". Feb 24, 2014 at 11:41

3 Answers 3

2

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.

1

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).

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.