C vs Python : A Comparison

Coming from C ,a programming language where you might come across lot of un-expectencies while coding, python might be termed as ‘lot easier’ to deal with for a beginner especially. For those who have programmed in C,python provides you with the great advantage of ‘not’ having to get into the system specifications such as ‘memory and bit’ manipulations. Ask those C programmers who would always say that the biggest challenge they have come across in C as a beginner is while they have dealt with pointers as if they are being taunted . Luckily ,specially for the starters ,python doesn’t require you to get into the memory allocation details and other stuff. All you need to do is to write your efficient code and wait for the result and most of the time the output you get wont give you a shock.

You could create a long list of points that might attract you to do a bit of coding in Python although C obviously has its own standouts. Some of them may be noted.

Python follows the Object oriented Programming paradigm whereas C follows Imperative programming paradigm.

Python has got a really large library as compared to C and a huge number of really powerful and useful built in functions.

Python code ,at first sight looks a lot more tidy than C because of its compulsory indentation requirement. You might know that this is not a necessity in C.

Python codes can be slower than corresponding C codes. Because python performs an ‘out-of-range’ checking for each iteration while looping ,the code becomes a lot more slower. This check has its own advantage though. Programmers in C would no that trying to access a location outside the allocation of an array would cause disastrous results.Python also performs the process of garbage collection which again decreases the execution speed.

The use of ‘for loop’ in Python is entirely different from that in C. The variable used is auto incremented and its important not to try and modify the loop variable of the ‘for’ loop.

There are no type declarations in python as is necessary in C.

Python does not support in-line assignment as in C. Therefore there is no chance of accidently assigning the value to a variable that you thought you were comparing.i.e ‘if a=5’ would just produce an error in Python whereas in C this would make the value of a equal to 5.

One of the major differences between python and C is that you wont get to play with pointers in python. Memory manipulation by the programmer is not required in Python as in C. Almost all the such activities done in C with the use of pointers can be done with sequences and associative arrays in python.

The variables used in python would result in an error without making an appropriate assignment. This proves really beneficial because unassigned variables can trouble you leading even up to segmentation faults in C.

Implementation of the ‘stack’ data structure becomes a lot more easier in python than in C. The implementation of ‘queue’ also becomes relatively easier. The python built-ins ;insert’,’append’ etc helps in the purpose.

Another important feature of python is the use of sequences ‘lists’ , ‘tuples’,strings’ and the use of Associative arrays. and their different manipulations. This helps programmers to do almost anything that can imagine of with the data stored.

Most importantly, python code is a lot more short than its corresponding C code. Programs that may take up to a few lines in a normal C code would give you the result in about 1-2 lines of coding in Python.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s