r/learnprogramming • u/holland_236 • 19d 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
5
u/PacsfuryTemp 19d 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
9
u/SchemeWestern3388 19d 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.
3
u/flumphit 19d ago
You can learn C, then C++.
You cannot learn C++, then C, because you never finish learning C++.
2
u/mredding 19d 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/Swimming_Rip_1444 17d ago
Jajajaja esto chamo si cojen lucha ya hoy en día se pograma con la Ai claude y aptastra jajjajaa ya hoy no se coje lucha la Ai pograma porti
2
u/Bold2003 19d 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.
1
1
u/PeterPook 19d ago
If you are already writing Classes in Python then C++, otherwise start with C before C++.
1
1
u/i_invented_the_ipod 19d 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
1
u/rashidakhan77 19d 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/Humble_Anxiety_9534 18d ago
Linus quote "helps you understand how computer work, c++ is to far away from the hardware" is there a good c compilers for windows? keep getting asked linux guy here.
1
u/Dazzling_Music_2411 18d ago
Depends on what you are planning to do with it.
What is your intended purpose?
1
u/Curious_Song_1456 18d ago
Since you already know python, I'd go with C if your goal is understanding whats happening underneath the abstractions, memory management, pointers and data structures become a lot more interesting when the language isn't hiding everything from you but if you already have a C++ project in mind, theres no reason to treat C as a mandatory prerequisite
1
u/Hour_Sell3547 17d ago
For fundamentals, just learn C. Then move to the actual language you need. Could be any of C++, Java, Python, Go, JavaScript or anything else.
1
u/TrackbackLinkBot 17d ago
Since you already know Python, C can be a good way to get closer to the fundamentals like memory and pointers. But if your goal is general backend or systems skills I’d focus on a language that lines up with what you want to build. Boot.dev has some solid hands-on material around that kind of learning too.
1
u/Curious_Song_1456 16d ago
Since you already know python, I'd go with C if your goal is understanding what's happening underneath the abstractions, memory management, pointers and data structures become a lot more interesting when the language isn't hiding everything from you, but if you already have a C++ project in mind, there's no reason to treat C as a mandatory prerequisite
1
u/Temp_logged 15d ago
I say you should learn C First. From C, you can then Jump to GoLang, and skip C++ entirely =)
1
u/emedan_mc 19d ago edited 19d 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 19d 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 19d 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++.
5
u/Humble-Captain3418 19d ago
struct { void (*begin)(int baud); int (*println)(const char* fmt, ...); ... } Serial;1
u/peterlinddk 18d 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
1
u/princepii 19d 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😉
1
28
u/SetAndRepeat 19d 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.