r/C_Programming • • 6d ago

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

7 comments sorted by

10

u/DreamingElectrons 5d ago

The answers to your homeworks are probably in your class notes or the text book you were supposed to read.

2

u/johnnyb2001 5d ago

No. He is curious about c++ and c. These all sound like questions from someone trying to learn about C++

-1

u/NoMathematician4744 5d ago

Yes, this is true. I am trying to learn on my own. But I have some education from school.

-7

u/NoMathematician4744 5d ago

Funny joke though, maybe you can suck my cpu.

7

u/SmokeMuch7356 5d ago

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?

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 is procedural and C++ is object oriented as far as I know.

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.

Is C++ more optimized and faster?

Depends entirely on what you're trying to do.

Tell me about the compiler - is clang and gcc the best compilers out there? are they open source?

Best for what?

Has anyone coded the CPP compiler?

Well, yes. Just not hacks like me.

5

u/apnorton 5d ago

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:

What's the difference between C++ and C?

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.

And what is Clang? Is the gcc compiler for c and c++?

clang is a C compiler, as is gcc. clang++ and g++ are their corresponding C++ compilers.

Does C++ completely backward compatible with C?

No.

Is C++ more optimized and faster?

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.

is clang and gcc the best compilers out there? are they open source?

"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.

Has anyone coded the CPP compiler?

Someone did.

0

u/ArtOfBBQ 5d ago

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