Which is Better C or C++?
Mayankjain last edited by
Hello All, I am start learning C programming language but till confused which programming language is good for my carrier? Which profile will make my carrier bright? Any suggest which one good C or C++
koahnig last edited by
Hi and welcome to devnet forum
This is not exactly a Qt related question.
C is older and also the basis of C++. C++ is object oriented and has therefore more possibilities to improve your programming.
This is a very rough statement. I suggest to google https://lmgtfy.com/?q=C+vs+C%2B%2B&s=g and check the responses. However, it is probably one of the longest fights which is better after C++ has been invented.
If you plan to use a library like Qt. You need to understand C++. When you understand C++ you basically have also the knowledge of C.
What would be your carrier? What kind of software are you going to develop? Because programming language depends on use case. For example: if you're going to contribute to Linux kernel then learn C, if you want to develop GUI applications learn C++, ...
techgeekbuzz last edited by
According to me or all the deveoper, Both are better for the beginning.
I always choose C++ because it is a superset of C. C++ contains all the features of C and in addition to that, it has Object-Oriented features. The new C++ specification(called as C++11) contains a lot more features like Threading, Synchronization, lighter version of garbage collection,..etc. If you choose C, then you have relied on the platform libraries(thread, win thread,..) for most of the works. But C++ provides a lot of utilities as part of its STL(Standard Template Library).
C++ abstracts the functionalities and exposes it in a nicer way
Consider a string operation,
const char* foo = "foo"; // char* is a language construct const char* bar = "bar"; char* foo_bar = malloc(strlen(foo) + strlen(bar) + 1); //to concat foo and bar, you need to allocate a memory strcpy(foo_bar,foo); strcat(foo_bar, bar)
std::string foo = "foo"; // std::string is a STL utility class. std::string bar = "bar" std::string foo_bar = foo + bar; // that's it :) + operator is overloaded in std:string // or std::string foo_bar = foo + "bar";
See the C++ code, it nicely abstracts the functionalities even though it does all magics behind the seen.
You can do the same functionality using both C and C++, but the significance is modularity and readability. C++ allows the programmer to concentrate on the real problem rather than diverting them.
Edit1: (Adding some details about Object-Oriented and Abstraction)
It is a programming paradigm, allow the programmer to think about the problem in terms of Objects and Classes.
It is very similar to a real-world classification based on the properties and behavior.
For example, Animal is a class. Human-being is a class. The vehicle is also a class.
Why they are all classes? because all those defines the set of properties and behaviors to a classified group.
In simple words, the class is a blueprint. (or Design time entity). Above example std:: string is a class.
The object gives real shape to a class. I and You are Objects of Class Human-being. Dogs and Cats are Objects of Animals. I and You also Object of Animals. Cars and Bikes are Objects of Vehicle.
In the above example, foo and bar are the Objects of Class std:: string.
Hiding the implementation details from the programmer. In the above string example, "+" operation abstracts the implementation details(memory allocation, string concat) from the programmer.
Standard Temple Library
It is C++ library which provides generic type-safe utility programs like string, list, vector, hashmap, automatic memory management(auto_ptr),..etc.
For example, you can quickly create a list of students like below,
std::list<Student> students; students.add(student1); students.add(student2);
For more detailed comparison in performance of C vs C++.
JonB last edited by
C is plain better (IMHO) :) But for your career, C++ is definitely more advisable!