Difference between .cc and .cpp file
In this tutorial, we will see the difference between the .cc and .cpp file extensions but first, we need to know what exactly .cc and .cpp is ?
Actually, there is no difference at all. The only difference is that you can type cc faster than cpp.
So, .cc and .cpp are both the extensions are used to store any C++ code. That means if we want to store particular C++ code in some file we need to use those extensions at the end of the file name(for ex – code1.cpp, code2.cc). Apart from these extensions, we have two more extensions that we can use to save a particular C++ code which are .cxx and .c++.
Let’s see by running them in Visual Studio to see if it works or not.
.cpp file –
//Save file with .cpp extension #include<bits/stdc++.h> using namespace std; int main(){ cout<<"This file save with .cpp file extension"<<endl; return 0; }
Output –
This file save with .cpp file extension
.cc file –
//Save file with .cc extension #include<iostream> using namespace std; int main(){ cout<<"This file save with .cc file extension"<<endl; return 0; }
Output –
This file save with .cc file extension
.cxx file –
//Save file with .cxx extension #include<bits/stdc++.h> using namespace std; int main(){ cout<<"This file save with .cxx file extension"<<endl; return 0; }
Output –
This file save with .cxx file extension
.c++ file –
//Save file with .c++ extension #include<iostream> using namespace std; int main(){ cout<<"This file save with .c++ file extension"<<endl; return 0; }
Output –
This file save with .c++ file extension
So these are the four extension files that we use to store C++ code. We can use any extensions that we want according to our requirements but try to avoid the .c++ extension because it may create problems for some tools but it will run perfectly in the Visual Studio platform.
Now let’s see some differences between .cc and .cpp file
- The most common difference between .cc and .cpp files is the different C++ file extensions. Just like we see in the above codes there is no big difference in output and in the structure of the code for different extensions. So, the whole structure of C++ code is the same and the only difference is different file extensions.
- In Microsoft Windows systems we mostly use the .cpp extension, while in Linux and Unix systems, we preferably use the .cc extension. But we can use them interchangeably and it won’t create a difference in the functionality of the C++ code.
- We can use .cc or .cpp extension according to our requirement it doesn’t affect the output of the code. The choice between them often depends especially in larger projects with multiple team members which helps to prevent errors and confusion.
Leave a Reply