What is the full form of .cpp extension?
Is it c plus plus or c preprocessor?

- 449
- 1
- 7
- 15
-
4The `.cpp` extension is meant to stand for "c plus plus". Independently, many compiler distributions include a program named `cpp`, for `c preprocessor`. This pre-dates the invention of C++. – Igor Tandetnik Aug 22 '20 at 18:13
2 Answers
File extensions have no intrinsic meaning. You can name a source file xyzzy.abc
and still compile it as C++ code. Just as you can take a MS Word document and name it foo.bar
and it's still a Word document. Extensions mean nothing apart from being helpful hints.
foo.exe
renamed to xxx.xy1
is still the same file with the same contents.

- 30,449
- 3
- 47
- 70
-
Can I ~~compile~~ a c++ code as foo.bar and not foo.bar.cpp ? Edit: I meant saved instead of compiled. – Ayush Basak Aug 22 '20 at 18:20
-
is it really possible to compile a file named xyzzy.abc as c++ 's source code ? how about this post :: https://stackoverflow.com/questions/5063266/javac-error-class-names-are-only-accepted-if-annotation-processing-is-explicitl – Papai from BEKOAIL Aug 22 '20 at 18:22
-
1@AyushBasak You can compile a file as C++ code no matter what the file name is. The file name doesn't *matter*. – Jesper Juhl Aug 22 '20 at 18:23
-
to add: it's always required extension to make compilation successful, i glad to know the reason behind of your answer @jesper – Papai from BEKOAIL Aug 22 '20 at 18:24
-
@Papai "is it really possible to compile a file named xyzzy.abc as c++ 's source code ?" - Yes. – Jesper Juhl Aug 22 '20 at 18:24
-
I understand extension names don't matter, but since people use the common '.cpp' extension, it should be some mnemonic. For example .xls is a mnemonic of Excel. – Ayush Basak Aug 22 '20 at 18:27
-
@AyushBasak It shouldn't *be* anything, it doesn't *have to* mean anything. It's just a convention. It does happen that the .cpp convention matches nicely with C Plus Plus, but it didn't *have to*. Many code bases also use ".cc" or ".C" (note the upper case), for C++ code. – Jesper Juhl Aug 22 '20 at 18:30
-
@JesperJuhl Thanks. I understand now. I was kind of confused because I had seen some people claim that .cpp officially stands for c plus plus. – Ayush Basak Aug 22 '20 at 18:33
-
1@AyushBasak "officially stands for" - according to whom? Who is "the official" ? – Jesper Juhl Aug 22 '20 at 18:35
-
@JesperJuhl nvm about that. But does it mean I can choose any random extension for a c++ source code? – Ayush Basak Aug 22 '20 at 18:38
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220275/discussion-between-ayush-basak-and-jesper-juhl). – Ayush Basak Aug 22 '20 at 18:39
What is the full form of .cpp extension?
There is no specification for this. It means whatever the author who wrote it means with it. When I write a c++ source file and give it a name ending in .cpp, I mean C plus plus.
Given that C pre processor doesn't convey meaning of C++ source file, and given that build systems generally assume .cpp to imply C++, it is reasonable to assume that those build systems do not interpret .cpp to mean C pre processor.
P.S. Another common suffix for C++ source files is .c++, which should be unambiguous. Yet another is .cxx where the plusses have fallen over. It is sometimes used by people who worry that + might not be valid in a file name.

- 232,697
- 12
- 197
- 326