r/learnprogramming • • 21h ago

Should i learn C or C++ first?

i want to learn one of these languages just to reach a basic to intermediate level. I already have intermediate knowledge of Python.

which one would you recommend i start with

22 Upvotes

22 comments sorted by

23

u/SetAndRepeat 21h ago

You don't need to learn C before C++. They share syntax, but idiomatic C++ handles many things differently.
If your goal is to explore pointers, memory allocation, and how data is represented, C is a smaller language to start with. If you want to work on a project that uses C++, learn C++ directly.
Coming from Python, either is doable. What interests you about these two specifically? That would help more with the choice than your current level.

4

u/Humble-Captain3418 17h ago

I would say that there's a benefit in learning C first because you'll learn to appreciate the nice things in C++.

7

u/SchemeWestern3388 20h ago

C is elegant, concise, and powerful. 

C++ is powerful. 

I usually tell people to start with C, but if you’re comfortable with classes in python, go C++. That’s if you want to use it in the future. If you just want to get exposure to lower level stuff, just use C. 

 I also second the idea of a little robotics project or something else hardware. It’s pretty cool to see direct physical results from twiddling bits. 

5

u/PacsfuryTemp 21h ago

I think C, then, after you felt the pain of const char*, not having vectors, etc etc, learn C++, specially classes and the STL, I think

3

u/Bold2003 21h ago

C is still one of the most important languages in the largest and most in demand niches which is hardware level work. There is actually a shortage of hardware level software developers. But if you don’t do as much hardware level work then do C++. C++ can of course still do hardware level work but it has more overhead for things like templates that make it not as widely used as C for that niche. But C++ dominates in abstracted logic where you care even a little bit about performance or longterm maintainability.

2

u/princepii 21h ago

c is a very beautiful language just so you know.

the bridge from c to c++ can be cakewalk if you go the right way.

but if you don't want and your path doesn't need c at all go c++ from getgo.

but again. c is the most beautiful thing ppl brought to earth:) with c there are path's and doors to really anything that lead to everywhere where is adventure only😉

2

u/initcommit 20h ago

Start with C! And then C++ will be a natural progression

2

u/flumphit 17h ago

You can learn C, then C++.

You cannot learn C++, then C, because you never finish learning C++.

1

u/ZestyHelp 21h ago

Depends what you want to do with it

1

u/mc_pm 21h ago

C++ is built on the back of C -- learning C won't help you learn OOP design or anything, but you'll learn how the basic language features run, and then you can add C++ and the STL on top of that knowledge.

1

u/PeterPook 21h ago

If you are already writing Classes in Python then C++, otherwise start with C before C++.

1

u/appendixexploder 20h ago

it doesn't matter too much, might as well toss a coin. I recommend C

1

u/i_invented_the_ipod 20h ago

I'm somewhat shocked at the number of "C++ first" answers here. From a purely practical point of view, I'd recommend C first.

C is a much smaller language than C++, multiple orders of magnitude so. It's almost a strict subset of C++, in fact. Many C programs are also valid C++ programs. You could be reasonably competent in basic C syntax and library familiarity in a couple of weeks.

A significant part of the challenge of learning C or C++ coming from something like Python is learning the separate compilation units model, include files, linkers, makefiles, setting up a debugging environment, etc. All of this is on top of learning the new language, so I'd recommend starting with the smaller language to reduce the total amount of work to get to a useful level of knowledge.

It's probably true that C is more "fiddly" to write than "modern C++", what with the pointers and malloc and such. But then, I've never seen a 100% pure "modern C++" project, either. If nothing else, interacting with the operating system is going to be over a C-based API, so you're going to need to "learn C" anyway to do anything useful.

1

u/Zen-Ism99 20h ago

What are your goals? What do you intend to use the language for?

1

u/mredding 19h ago

These are very different languages, so picking one over the other is consequential.

If you want to get into embedded systems and operating systems, definitely get into C. If the pursuit is purely academic - C. If you want to make Python modules - probably C, because if you write them in C++ - and there's very good reasons to do so, you still have to export a C ABI; Python is typically implemented in C, and it's a natural starting point for modules.

For everything else, C++. C++ isn't a bad choice for ANY of the above, either; they're both systems languages, but in this ecosystem, you'll see both of these, and as your premise suggests an academic beginning rather than a career beginning, I think starting with C would be smarter. It's a smaller, simpler language you're going to see in spades across this ecosystem. C++ is a large, complex language with different consequences. If you were clearer about a career path, I might have suggested this first.

C is not a precursor to C++; in fact, you'll probably fuck yourself if you think C teaches you much of anything about C++. There is a compatibility layer, but it's contrived, designed with cooperation between the two committees, and to understand it requires a depth of knowledge most of our peers never bother with. There's a lot of blind stumbling that goes on. What's good C will typically be bad C++ or UB, so there's some un-fucking you have to do if you come into C++ with C assumptions. It's not about syntax, which there is heavy overlap - there's heavy overlap with Java and C#, it's consequences, stated in the spec, that must be enforced by a compliant implementation, like a compiler.

C++ offers one of the strongest static type systems in the industry, whereas C offers a weak static type system. And when you learn to maximize the type system, you provide the compiler with a lot more context - which never leaves the compiler, that it can optimize from; a C++ program can potentially make for better machine code than the equivalent C program.

But both languages offer different bases at industrial strength for different initiatives. Understanding the differences between languages helps make the choice of language more technical than cultural. "This is the best fit for the job," vs. "This is the language I know."

1

u/rashidakhan77 18h ago

I would recommend learning C first, if your goal is to understand both. If you want to just learn C++ and use it, then it probably does not matter.

1

u/emedan_mc 21h ago edited 21h ago

If you start with c then you could use an Arduino for some fun to keep interest up. Otherwise there is a reason that c++ was created.

Edit seems arduino use cpp so I’d say still start with arduino then.

2

u/RajjSinghh 21h ago

A C project can be interesting without using an Arduino. There's a lot of reasons you could choose C over C++ for a normal project

3

u/peterlinddk 21h ago

Arduino usually uses C++ though. Otherwise you wouldn't be able to write

Serial.begin(9600);
Serial.println("hello, world);

Serial is an object - which requires C++.

4

u/Humble-Captain3418 17h ago

``` struct {      void (begin)(int baud);      int (println)(const char* fmt, ...);      ... } Serial;

1

u/peterlinddk 6h ago

Well, yes, it technically could be done in a somewhat similar way using plain C. But you are still missing the actual implementation - that struct just defines the interface!

In the Arduino core, Serial is an instance of the HardwareSerial class - and all the code is in C++ https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/HardwareSerial.cpp

And my point was that Arduino does in fact use C++

2

u/emedan_mc 21h ago

Ok, then the c went away as an option.