.cc or .cpp: Which Extension to Choose for C++ Code?

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: One Language — Dozens of Extensions

\n\n

If you are just starting to learn C++, you have probably encountered this situation: you look at a tutorial or code example on GitHub, and the files are named sometimes main.cpp, sometimes utils.cc, and occasionally even program.cxx or source.C. A natural question arises: "What's the difference? Are these different languages? Or just someone's whim?"

\n\n

You are not alone. On Stack Overflow, the question "C++ code file extension? What is the difference between .cc and .cpp" has gathered hundreds of thousands of views. And this is not surprising: even experienced developers sometimes get confused by these seemingly trivial details. Today, we will finally sort out this puzzle. You will learn where the different extensions came from, whether there is any technical difference between them, and which extension a beginner should choose.

\n\n

Short Answer: No Technical Difference

\n\n

Let's clear up the main point right away. From the perspective of the compiler and the C++ language, there is absolutely no difference between .cc and .cpp. They are just two different ways to tell the operating system and build tools that they are dealing with C++ source code.

\n\n

Compilers (GCC, Clang, MSVC) understand both extensions. You can take a file hello.cc, rename it to hello.cpp, and compile it without a single change in the code. Here is a simple example:

\n\n
// File: hello.cc\n#include <iostream>\n\nint main() {\n    std::cout << "Hello from a .cc file!" << std::endl;\n    return 0;\n}
\n\n

You can compile it like this:

\n
g++ hello.cc -o hello
\n\n

And now let's rename it to hello.cpp:

\n
g++ hello.cpp -o hello
\n\n

The result will be identical. The compiler doesn't care what the file is called — only its contents matter and that you explicitly specify the language (or the compiler guesses it from the extension).

\n\n

Historical Origins: Where Did .cc and .cpp Come From?

\n\n

To understand why there are so many extensions, we need to look into history. C++ was created as an extension of the C language. The first compilers (e.g., Cfront) were simply preprocessors that translated C++ into plain C.

\n\n

The .cc Extension — Unix Legacy

\n

In Unix-family operating systems (and particularly in early versions of AT&T Unix), a tradition developed of using short, two-character extensions. This was due to file system limitations: for example, in s5fs (System V), the filename length was severely restricted. Thus appeared:

\n
    \n
  • .c — for C files
  • \n
  • .cc — for C++ files (C + C = CC)
  • \n
  • .h — for header files
  • \n
\n

The .cc extension became the de facto standard in the Unix and Linux world. Many large projects (e.g., Google Chromium, LLVM) still use it today.

\n\n

The .cpp Extension — The DOS and Windows Era

\n

When C++ began to gain popularity in the PC world, the DOS and early Windows ecosystem emerged. The constraints were different here, but another need arose — to make the extension as clear as possible. .cpp stands for C Plus Plus — a direct reference to the language. This extension became popular thanks to:

\n
    \n
  • The Borland C++ development environment
  • \n
  • Microsoft Visual C++
  • \n
  • C++ textbooks and books (so beginners would immediately understand what they were dealing with)
  • \n
\n\n

Other Traveling Extensions

\n

Besides the two main contenders, you can encounter other extensions in the C++ world:

\n
    \n
  • .cxx — another variant of "C++", popular in some Unix systems (e.g., IBM AIX)
  • \n
  • .C (uppercase C) — used by some compilers to distinguish between C (.c) and C++ (.C) on case-sensitive systems (e.g., in old

Blogs

Book Recommendations