r/C_Programming • u/NoMathematician4744 • Sep 29 '26
C++ vs C
What's the difference between C++ and C?
And what is Clang? Is the gcc compiler for c and c++?
Does C++ completely backward compatible with C?
C is procedural and C++ is object oriented as far as I know.
Is C++ more optimized and faster?
Tell me about the compiler - is clang and gcc the best compilers out there? are they open source?
Has anyone coded the CPP compiler?
Thanks,
Dennis
0
Upvotes
11
u/DreamingElectrons Sep 29 '26
The answers to your homeworks are probably in your class notes or the text book you were supposed to read.
7
u/SmokeMuch7356 Sep 29 '26
++No. There are legal C programs that are not legal C++ programs, and there are legal C programs that are legal C++ programs but have different behavior.
C++ natively supports object-oriented programming, C does not. You can write procedural (and functional) code in C++, and you can write object-oriented code in C, it's just a shitload of work.
Depends entirely on what you're trying to do.
Best for what?
Well, yes. Just not hacks like me.
5
u/apnorton Sep 29 '26
A lot of these questions have readily available answers elsewhere online; it might be worthwhile searching for some of them. However, I can give a high-level answer to these:
They are two different languages with a significant overlap in syntax/semantics, but the overlap does not mean they are the same. C++ was developed to be an improvement on C, and features native support for object oriented programming structures, among other things.
clang is a C compiler, as is gcc. clang++ and g++ are their corresponding C++ compilers.
No.
No, though there are (what Stroustrup calls) "negative-cost abstractions" in which you might be able to employ abstraction in C++ in a way that allows for optimizations better than the non-abstract version of the code. But, unless you're in an insanely niche scenario, toolchain support/libraries/target environment/coworker knowledge are far more important than any kind of optimization difference between the compilers for the languages.
"Best" is a wishy-washy word. They are both perfectly suitable general-purpose compilers. You might need to use different ones at some point in a career, but if you have reason to do so, you'll know.
They are also both open source.
Someone did.
0
u/ArtOfBBQ Sep 29 '26
Dear Dennis,
C and C++ are both agreements that people invented. "When you write code like this, it should turn it into a program that behaves like this"
The crucial difference is that the C++ agreement is so complicated and big that no one on God's beautiful earth actually understands it
gcc and clang are both compilers. Compilers are programs that turn a piece of text into a program if the text follows the agreements
No, C++ is not "more optimized" or faster than C.
Yes, compilers are also just programs, so someone made them
Kind regards,
Billy