Difference between C++ and Python

Well since http://candcplusplus.com provides both C++ and Python tutorial this post will point out some of the differences between C++ and Python programming language.

All the differences between C++ and Python is not mentioned here,only some of the major important features which you must be aware of by all means if you are learning both the languages are mentioned.

i)Which is faster?

In case of speed C++ is faster than python,why?

C++ uses a system known as compilation.In this process all the codes in your program are checked thoroughly for any errors and if the code demands it allocate memory ,optimizes the instruction and make everything ready to be converted to another file known as executable file.Once the executable file is obtained the executable file is run.Simple isn’t.

In case of Python there is no process such as compilation.All the errors in the code are check when the program starts running.Also all other process like memory allocation,code optimization,etc. are done only when the program starts running.Again all these process occur for every statement in the program.Hence Pyrhon is slower than C++

In short Python does more work while running the program than C++ does.More work means more time consumption hence slower.


Static and dynamic

C++ is statically types language while Python is dynamically typed language.

By static we mean all the data type in the program are known and checked before running the program.This is also done during the compilation process.For instance in C++ code.

int i1=89 , i2=90 ; //int means integer

cout<< i1+i2 ;

The type of i1 and i2 is known.By knowing we mean the compiler knows about it(We programmer of course knows it).

Python is dynamic.This means the data type are not known before hand.The type of data come into light only when the code is run.For instance in Python program.

>>> i1=89 #type not known
>>> i2=90 #type not known
>>> i1+i2
179

The type of i1 and i2 are integer type but it is known only when the program is run.



Faster development

Program can be developed faster using Python than with C++.One of the reasons for this is with Python we can write program with shorter codes.

To prove that Python codes are shorter let us write a program to swap two values.The first program is using C++.

int i1=12 ,
 i2 =34 ,
 c;

/** Swapping codes **/
c=i1 ;
i1=i2 ;
i2=c ; 

cout<< i1 << "  " << i2;

As you can see there are three lines involved.

The code below shows how to swap values in Python.

>>> i1=12
>>> i2=34
>>> i1, i2 = i2 , i1 #Swapping value
>>> i1
34
>>> i2
12

In Python as you can we need only one line of code to swap values.


Specific uses

If you want to build a big architecture software or big games like FIFA,GTA you definitely need C++(may be implicitly in case of Games development).What it means is C++ can handle any big software or hard ware programming,even Windows is built using C++.

Python on the other can be also use to built software but it’s influence is lesser than C++.Python is mainly directed towards building database,web application.Python has mainly to do with web and it’s products.

Python is also good in blending different languages together.


Language specificity

Python has an automatic memory management system.In Python you need not track every code of deleting the memory once the data is no longer required.Everything is automatic.

In C++ you have pointers or even smart pointer system to manage memory.If the programmer misses out to delete a memory there is a risk of memory leakage.But this should not worry you because the language has many features to make the programmer write code efficiently without taking any risk.





Leave a Reply

Your email address will not be published. Required fields are marked *