Why do all the C files written by my lecturer start with a single # on the first line?

Wow, this requirement goes way back to the 1970s.

In the very early days of pre-standardised C, if you wanted to invoke the preprocessor, then you had to write a # as the first thing in the first line of a source file. Writing only a # at the top of the file affords flexibility in the placement of the other preprocessor directives.

From an original C draft by the great Dennis Ritchie himself:

12. Compiler control lines

[...] In order to cause [the] preprocessor to be invoked, it is necessary that the very first line of the program begin with #. Since null lines are ignored by the preprocessor, this line need contain no other information.

That document makes for great reading (and allowed me to jump on this question like a mad cat).

I suspect it's the lecturer simply being sentimental - it hasn't been required certainly since ANSI C.


Does Nothing

As of the ISO standard of C/C++:

A preprocessing directive of the form

# new-line

has no effect.

So in today's compilers, that empty hash does not do anything (like- new-line ; has no functionality).


PS: In pre-standardised C, # new-line had an important role, it was used to invoke the C Pre-Processor (as pointed out by @Bathsheba). So, the code here was either written within that time period, or came from habit.


Edit: recently I have come across codes like this-

#ifdef ANDROID
#
#define DEVICE_TAG "ANDROID"
#define DEBUG_ENABLED
#
#else
#
#define DEVICE_TAG "NOT_ANDROID"
#
#endif /* ANDROID */

Here, those empty hashes are there only for making the code look good. It also improves readability by indicating that it is a preprocessor block.