r/cpp_questions • u/one-for_all • Jun 04 '26
OPEN C or Cpp
Should I learn C before Cpp? I have a basic understanding in python ( very basic) and nothing much else, is it recommended to do Cpp directly?
6
Upvotes
40
u/khedoros Jun 04 '26
I'd go right for C++, so that you don't have to unlearn habits picked up in C.
5
u/Thesorus Jun 04 '26
learn C++;
why do you want to learn either C or C++ ?
10
u/bearheart Jun 04 '26
I’m old. I learned C before C++ existed. I’ve found the foundation of C to be useful. Not only with C++ but with so many languages that are based on C.
Learning C first is certainly more work. And there are differences and distinctions. But if you’re up to the challenge I think it will make you a better programmer.
Many people disagree but that’s my experience.
1
u/one-for_all Jun 05 '26
Seems like 50 percent prefer C first and C++ later and 50 percent suggest C++ directly 🥲
5
u/Zwischenschach25 Jun 04 '26 edited Jun 04 '26
If you want to be a C++ programmer, then learn C++. I know that technically speaking it's a superset of C, but in the real world they're different languages. I've been a professional C++ programmer for 3-4 years but I wouldn't feel remotely qualified for a job that asked for experience in C.
5
u/DankPhotoShopMemes Jun 04 '26
it depends what your goal is.
if your end-goal requires C, learn C. Don’t try to start with C++ to make it easier.
If your end-goal requires C++, learn C++.
So what you really gotta ask is which language better fits your needs. If you’re not sure, you should do a bit of research into both languages and find out what’s more applicable. (or just ask on here :))
4
u/[deleted] Jun 04 '26
No, go straight to C++. HOWEVER learn the standard C library, in particular GLIBC because it is the workhorse that moves C++
1
u/Interesting_Buy_3969 Jun 05 '26 edited Jun 05 '26
If the goal is certainly C++ and not C, then head off to C++.
C and C++ differ conceptually. Both provide low-level control, but C is more explicit and "raw", whereas C++ adds OOP, generic code, and plenty other higher-level complex but convenient features. Although C++ still supports almost all of C syntax because C++ originally was designed as a C superset.
2
u/alfps Jun 04 '26 edited Jun 04 '26
C++ and Python complement each other. The C++98 standardization process with "papers" was modeled on Python PEPs. The C++23
std::enumeratesupport for range based loops comes more or less directly from Python, with the same name. And so on. The main difference is that C++ is a value based language while Python is a reference based language, so e.g. in C++ you havestd::swapto swap the values of two variables; no such thing possible in Python.Since you're used to just using stuff where you don't know the detailed implementation, C++ can be a good choice. E.g. you can use
std::vectorfor dynamic arrays andstd::stringfor strings and not think about it.In C you have to reinvent all those wheels. Python comes with batteries included; C++ has some machinery but you have to supply the batteries and connect the parts; C lacks everything but the hard core of the language, the built-in constructs.
Well, strings can be handled in C via functions such as
strcmp. So while in C++ you can writes1 >= s2just as in Python, in C you write e.g.strcmp( s1, s2 ) >= 0. It is a lower level of abstraction and some people perceive that as simpler, while some other people (including me) perceive that as more complex.Anyway, if you learn C first then you need to unlearn both technical stuff and idioms and general approaches to things in order to use C++.
So I recommend C++, but some others recommend C, and probably one or the other will be best for you but impossible to predict…
Some code constructs are technically valid in both C++ and Python but mean different things.
In particular, beginners coming from Python have written
min <= x <= maxin C++. But in C++ it doesn't have the mathematical meaning min ≤ x ≤ max. Instead it's parsed as(min <= x) <= max, where the boolean result of the first sub-expression is converted to integer 0 or 1, which is compared withmax, which is usually totally meaningless.So, in C++ that has to be written as e.g.
min <= x and x <= max.Another gotcha is that in Python integer division rounds towards negative infinity, so that
7//-2yields −4, while in C++ integer division rounds towards zero, so that7/-2yields −3.Oh, and that leads to a third difference: in C++ there is no dedicated integer division operator. There is just
/, which does floating point division or integer division depending on the types of the arguments. That can take some getting used to!2
u/Independent_Art_6676 Jun 05 '26
C will just teach you stuff to unlearn as many of the things you do in C are legal but 'bad code' in c++. Examples are macros, raw pointers, heavy use of pointers, DIY data structures where a built in one exists, free for all type punning, excessive/unnecessary bitwise code, and more. In the mid 80s C first made sense, but today its like telling someone to learn latin and german first before learning english to make it "easier".
1
u/TheCatholicScientist Jun 05 '26
Kate Gregory - Stop Teaching C
1
u/UnicycleBloke Jun 05 '26
There is no advantage to learning C first, and arguably some disadvantages. C and C++ have a common ancestor but are really very different creatures. That was true in the early 90s when I started using C++ (I ignored C except that I needed to read Win32 examples). It is more true now.
This comes up quite often. Can we add something to the sidebar?
1
u/iamafkalot Jun 05 '26
C is pretty awesome but C++ will do ya one better
1
u/CryAlert1725 Jun 08 '26
what is the question? It's obvious that CPP is more advanced, and C is literally its father. without one, the other couldn't exist, but if you're choosing based on the existence of both versions, the choice is obvious.
1
u/heavymetalmixer Jun 11 '26
Yeah, learn C first, make your fundamentals stronger. C++ is a very complex language and it's better if you know how and why each cog works. I recommend C17, or at least C99. C89 doesn't have "Strict Aliasing" and that can make you used to things that lead to you UB really often.
1
u/manni66 Jun 04 '26
Stop Teaching C
1
u/Undeniable_Dilemma_ Jun 04 '26
Learning C is both, a gift and a curse. I started with C, fell in love with it, it shaped my brain in a certain way.
Years later, still trying to get into C++, wrote some C++ here and there but man I just hate it and can't get over it, and always go back to C. Also looking into alternatives and considering switching to Zig.
I wouldn't say I mind that, I simply value different things now, than I would've if I started with C++ directly. It's just a matter of perspective.
It's not necessary, if you just wanna go into C++, you'll have a better time avoiding C altogether. Is that a good or a bad thing? Who knows. It's a matter of the way you look at things and your philosophical approach to programming languages. Both languages are capable of phenomenal things, so it ultimately doesn't matter that much. You can do anything in either.
0
u/[deleted] Jun 06 '26
[removed] — view removed comment