Where to put include statements, header or source

cheaderinclude

Should I put the includes in the header file or the source file? If the header file contains the include statements, then if I include that header file in my source, then will my source file have all of the included files that were in my header? Or should I just include them in my source file only?

Best Answer

Only put includes in a header if the header itself needs them.

Examples:

  • Your function returns type size_t. Then #include <stddef.h> in the header file.
  • Your function uses strlen. Then #include <string.h> in the source file.