What’s the difference between C# and C++ in the code itself?

3.00K views
0

I know that C# is oop, and C++ isn’t, and I know that garbage collection is easier in C#, but what are the actual differences in how lines are written, and why pick one over the other?

EDIT: to clarify, I have c# experience, and I’m considering picking up C++, but whenever I google it, it gives me only the obvious surface level differences

In: Other

Despite the names, C# and C++ are completely separate languages.

C++ is also object oriented, although not as strictly as C# – as an extension of C it still supports C style functions (function without a class), but it has classes just like C#.

Regarding garbage collection in C++ – there is none. You have to keep track of memory that you allocate, and remember to free it when you’re done using it.

Why pick one over the other? C++ is a little closer to the actual hardware, so you can more easily write code that interacts with it (for example software drivers are usually written in C or C++). Game engines are also often written in C++. Otherwise there isn’t a lot of reason to choose it over C++.

One thing you must remember is that a programming language is just a tool, not a target. An experienced programmer should be able to pick up a new language in a matter of days.

> I know that C# is oop, and C++ isn’t

What? Both are OOP.

> I know that garbage collection is easier in C#

That’s because there is no garbage collector in C++, you need to dispose of stuff manually.

> but what are the actual differences in how lines are written

They are different languages. It’s like asking what’s the difference between how lines are written in Java and C#. There are many similarities between the syntax of C# and C++ though. C++ has pointer and references. Things you don’t need to worry about in C#.

> and why pick one over the other?

Depends on what you are doing. There are certain frameworks that work with C++ but not C#. For example the QT GUI framework. On the other hand, the Unity game engine works with C# and Javascript and not C++.

I think it’s safe to say that C++ is more performant but whether or not you really need this performance advantage depends on what you are doing.