Neither the C nor the C++ language (and please remember that they're two different languages) has any rules for source file names. Both specify the names for their standard headers, and follow certain conventions for those names, but those conventions are not imposed on other source files. (Note that standard headers are not necessarily even implemented as files.)
An operating system, or a file system, or a compiler, or some other part of the environment might impose some requirements.
More specifically, Unix-like systems typically permits any characters in file names other than '/'
(which is the directory path delimiter) and '\0'
(which is the string terminator), and compilers typically permit any valid file name (possibly paying attention the extension to determine which language to compile). Windows disallows some other characters. Case-sensitivity varies from one system to another; foo.c
and Foo.c
may or may not name the same file. The latter can be significant for foo.c
vs. foo.C
; sometimes .C
is used as an extension for C++ source. Use something else if your code might be used on a case-insensitive file system (Windows, MacOS).
There are a number of conventions for file extensions used to identifier the contents of a source file, such as .c
for C source, .h
for a header file, .cpp
or .cc
or .cxx
for C++ source, and so on. Consult your compiler's documentation.