Although C++ is an improved version of C, there are a lot of differences between C and C++. In this post, I have outlined the differences between C and C++ in ten plus one points that can be asked in interview questions on C and C++.
- C does not have any concept of classes or objects. It is procedure and function oriented. There is no concept of access through objects and a structure is the only data type where there is a access through a compacted variable. C++ is object oriented.
- C structures have a different behavior than C++ structures. Structures in C cannot contain functions.
- C i/o is based on library functions. C++ i/o is made through the cin and cout operators.
- C functions do not support function or operator overloading. In operator overloading, the same function has two or more behaviors based on their parameters.
- C does not support new or delete commands. The memory operations to free or allocate memory in c are carried out by functions like malloc() and free().
- Undeclared functions are not allowed in C++. The function needs to have a prototype before the main() before first use in C++ although in C, the functions can be declared after main(). There is no need for a prototype to be defined before main.
- For an int main() in C++ we need not write a return statement but the return is mandatory in C if we are using int main().
- In C++ identifiers are not allowed to contain two or more consecutive underscores in any position. C identifiers cannot start with two or more consecutive underscores, but may contain them in between words.
- C has a top-down approch whereas C++ has a bottom up approach while parsing.
- In C, a character constant is automatically elevated to an integer whereas in C++, this is not the case.
- In C declaring global variable is allowed several times but this is not allowed in C++.
Do you think there are some more differences between C and C++. Please share them with us. In future, I will also tell you why C is not a high level language and is actually a low level programming language.