Introduction
Since in our first part of this article we said we expected you, the reader, to have some programming knowledge, in this part we want to help you get a on where C stands in comparison to other programming languages you might know. The choice of those languages was pretty tough because of various criteria, but in the end we stopped at C++, Perl and Python. Since programming languages can be classified in lots of ways (depending on paradigm, syntax or style, for example), we didn’t try to find languages that are in the same category as C. Instead, since the aforementioned languages are pretty popular in the Linux world, we chose them, mentioning what every language’s place is in the great scheme, what it’s generally used for and of course, the differences between them and C. This article will be structured as follows: we’ll start with important elements of every language, like variable declaration, typing or structure and compare that with how it’s done with C. Thusly we hope to give you an idea about the language before we start. The parts this article is made of will be exactly like the announced structure of this article, to make comprehension easier.
The comparison
Types, operators, variables
C++
C++ was initially named “C with classes”, which says a lot about its’ relation with C. It is widely seen as a superset of C ( thus C++ the unary increment operator ++ ) , introducing object-oriented programming features. Types are essentially used the same, with bool being introduced in C++ for boolean operations. Basically, when talking about C and C++ differences, most of those come from the OOP concepts C++ has and C does not. For example C++ has operator overloading, an OOP-specific term, which means that an operator may have different implementations depending on the data it’s operating on. For example, in C++ you can do this:
a << 2
Now, if a is an integer, this will do a bitwise operation on it (left shift by 2), but if a is an output stream, the above line will try to write a ‘2’ to it. This kind of behavior is one of the reason C++ is criticized for allowing poor programming practices. Variables and constants are declared the same way as in C.