r/cprogramming • • 15d ago

I'm just learning C basics. Should I switch to C++ because my friend recommended it?

[removed]

26 Upvotes

73 comments sorted by

38

u/Hkiggity 15d ago

I code in c++ primarily. I’d recommend just sticking with C for now. Ur a freshman in college, you can learn c++ down the road.

Your friend isn’t exactly wrong that it probably has more opportunities bc it’s used in many fields. But being good in C or c++ is a false dialectic. Keep learning C and pick up c++ down the road. Even if it’s in 6-12 months.

C++ is very verbose. Being good with C will help anyway

9

u/Stock_Test2326 15d ago

"..Ur a freshman in college, you can learn c++ down the road.."

this.

just make a roadmap, you have a lot of time during college years. just make most of it OP while living a life little.

1

u/AdreKiseque 12d ago

(False dichotomy*)

11

u/skoomaking4lyfe 15d ago

Learning C will teach you the same basics of programming that C++ will, which is what you're doing in your 1st year of college. If there's some other reason to switch, then do so for that reason. But all you're doing is learning about loops and pointers and memory management and so forth, and C works perfectly well for that.

9

u/Confused-Armpit 15d ago

I would argue it works even better for that because there is very little hidden machinery. Deconstructors for classes, operator overloading, templating, or even something like std::string all hide complexity.

11

u/alkavan 15d ago

C and C++ are very different programming languages, although sharing somewhat common syntax and keywords.

C is procedural, C++ is multi-paradigm (procedural, generic/meta, OOP, functional), C has 30 useable keywords, C++ has over 50. C is easy to learn, hard to master, C++ is hard to learn, almost impossible to master. People sometimes say "you don't learn the whole of C++ just what you like and require" — true, however to understand what is the correct slice you should learn you need 10 years of experience. C is a good base for C++, but C++ is not the same for C.

You can learn C to a decent level in months time, but learning C++ to a mediocre level takes 10 years.

With that been said, for certain size and type of projects C++ makes more sense, but it's not the kind of projects you or your friend will work on any time soon I suspect.

The bottom line is, start with C, you can build almost unimaginable amount of cool and useful stuff with it, learn it good, practice it well, use a proper IDE — not VSCode or anything like that.

Unless your friend is extra smart, he'll get frustrated pretty fast, while you'll be building cool shit. It doesn't mean you can't learn C++ later, it will be much easier.

Disclaimer: I daily work with C and C++ and like both.

7

u/SeaEntrepreneur9092 15d ago

The biggest mistake I made was doing such things and googling a lot. If I would start again from first year I would definitely learn c deep not just the language but hardware concepts like memory management and also master computer science subjects

6

u/henryyoung42 15d ago

Stick with C for the time being, but also realize that programming languages are tools in what becomes an ever widening tool box. The best tool for a job is guided by deployment architecture, problem domain, solution lifecycle, dependent API binding availability, etc. What you are really learning are coding patterns, algorithms and data structures which are mostly independent of a specific language’s syntax.

6

u/hoschidude 15d ago

Stick with C.

If you're firm in C switching to C++ will be easy.

1

u/henryyoung42 15d ago

I think you mean easier ;)

10

u/sswam 15d ago

C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C.

-- Linus Torvalds

https://lwn.net/Articles/249460/

Even if you do eventually decide to use that horrible language C++ for some reason, such as getting into AAA games programming, I recommend that you stick with plain C until you master it first.

1

u/henryyoung42 15d ago

I agree with Linus. I recall one developed I used to employ who would build solutions with an infinite number of infinitesimally small abstractions, using C++ templates where ever possible. His code was literally 90% decoration and 10% actually doing anything. Admittedly it still performed as well as a version with everything collapsed and inlined thanks to optimizing compilers, but was a nightmare for others to maintain without the ability to transplant the current state of his eidetic memory. The moral of that story being, write clear and easily understood code (easily understood on first contact by those who come after you), don’t try to be too smart.

That said, the age of AI of moving those goal posts … god knows where eventually.

16

u/an0th3rbrick 15d ago

no. c++ is a total disaster of a language

-4

u/juabit 15d ago

you dont know what you are talking about do you.

1

u/MetalInMyVeins111 15d ago

Seems like you're the one not knowing what you're talking about.

4

u/Abdqs1234 15d ago edited 15d ago

C is perfect for building good basics as it forces you to do everything on your own, and as a language it's not as complicated so you'll probably understand whatever your doing with it as it doesn't have a lot of abstraction. C++ on the other hand offers a lot of features that supposedly make many aspects of programming easier and allow you to dip your toes into a lot more things easier, such as game design or quantitative finance. The catch being that, learning and understanding most of those features takes a lot of time and overall the language is a lot more complicated and as such in some aspects unpredictable and with a very steep learning curve. In fact it had me spinning my head when I was trying to learn it abd realizing I hadn't even covered the surface of the amount of features the language had.

At the end of the day with enough knowledge whatever you can do with c++ can be done with c and vice versa. C offers simplicity and low abstraction, requiring you to do everything manually. C++ offers loads of features that can make life easier but are hard to understand.

4

u/Mediocre-Pumpkin6522 15d ago

Continue with C and pay attention to structs. When you move to C++ the classes with methods combined with structs will make more sense. The problem with C++ is many rabbit holes have been added to the original 'C with Classes' philosophy and many references go chasing rabbits down holes you may never use because they are kool.

4

u/l_tonz 15d ago

c is a great language for learning… switch to c++ to be more productive and after you learn the fundamentals in data structures

3

u/LemonLord7 15d ago

I think you should stick to C, then learn C++ for job opportunities and widening your competence in coding, then going back to C and see how you can implement the tools that C++ gives you in pure C.

I don’t know the job market of where you live, but being good at C is not needed to learn C++ but it will make difficult parts of C++ easier to understand.

3

u/__rituraj 15d ago

Whether you are poanning for opportunities in C++, Rust, Go, Python or whatever,

Master fundamentals in C first, before moving onto others.
You'll understand programming at a much deeper level.

2

u/dvhh 15d ago

It really depends toward which direction you want to go to, but honestly it does not hurt to learn a variety of language, that is if you start learning C++, do not drop C, knowledge of both language and how they differs really help in situations where you have to mix them ( and there is a lot of them ). One issue though is that the breadth of the C++ language is quite large and encompass a lot of concepts.

there are also a lot of facilities in maintaining quite large projects in C++. And depending on who you ask , a lot of boilerplate code get covered by some of the C++ constructs.

Other modern language inherit a lot from C++ concepts, and also what to avoid.

However if you only have time for one, I'd stick to C. Short of learning assembly, it helps you a lot in understanding how programs work under the hood. C++ already have a lot of hidden implicit behavior and it can make it difficult to understand the flow of a program due to initialization steps occur at multiple point in a code lifetime.

2

u/Soft-Marionberry-853 15d ago

Im not going to say one is better than the other but I will say its probably best to stick with one until you get a good grasp of the fundamentals of programming,

2

u/tredbert 15d ago

Definitely start with C and stick with it for a while before switching to C++. It will teach you all of the fundamentals of programming without the crap that modern C++ has in it.

After you have gained a mastery of C then learn C++.

2

u/UnicycleBloke 15d ago

I have mostly used C++ for decades, but learned C along the way.

C++ is a much more expressive language with far better tools to eliminate a lot of perennial bugs found in C (you can still make the same bugs in C++, but they are easier to avoid). The downside is that C++ is a much larger more feature-rich language (and the standard library) and it takes longer to become competent. You don't need to know everything but there is definitely more to learn.

It is important to understand that C and C++ are very different creatures with very different idioms and practices. Writing C but with a few C++ features chucked in is sadly how C++ is often taught, and that is best avoided. I don't know whether C++ has more job opportunities, but it has plenty.

You can build strong fundamentals in both C and C++. Much as I prefer C++, you might be better off sticking with C for now. I learned C++ first and it worked out well, but do what works for you. Not to muddy the waters, but in your position I would seriously consider Rust as well. :)

2

u/No_Mail_9869 15d ago

I don't think you have to switch just because your friend recommended you, but it's worth getting a look at other languages. If you are on a basic stage, you don't have to do this now, any languages works on this level, but once you get familiar to the basics, is worth trying C++ and some other languages if you want to. I don't know if you knew this, but C and C++ are different languages, they look very similar, but the way you code is a bit different, of course you can code in C++ like you code in C, but I don't think it's very recommended doing this when you're working, I do this sometimes, but just on my personal projects.

2

u/peccator2000 15d ago

If you are good in C, moving on to C++ is not too hard. Learning C well has no downsides so why stop?

4

u/kutac56 15d ago

No, c++ is a mess of a language. First learn c basics and then also learn c++. It ain't better but sometimes OOP is wanted so that's chosen

3

u/Raychao 15d ago

If you learn pure C first, you will appreciate C++/Java much more

2

u/Traveling-Techie 15d ago

My problem with C++ is that it seems to make it easy to develop bad habits. I can’t really explain it but it seems like it takes a lot of self discipline to write good clean well designed code. The language that I used to learn better OO design was Java. Maybe it was happenstance but I’ve talked to other programmers who have had similar experiences.

1

u/No_Context2723 15d ago

C is great for fundamentals. What do you want to do with a programming language? Do you want to do game development? Web development? Pick whatever language suits what you want to do.

1

u/CS_70 15d ago

Hmm what about using your head and find out what suits best what you want to do ? It's kinda of a requirement for programming... :D

But in short: no. C is a well though, consistent, straightforward and coherent. C++ is .. not. Learn to walk from A to be before learning to make backwards spins flipped upside down to go to the same place (and consider that you most likely dont need to).

1

u/ComradeGibbon 15d ago

You should pick go, C# or Swift over C++

1

u/3lml 15d ago

It's very much a matter of your taste, needs and goals. If you lean towards high-level languages C++ might be better. If you're more interested in how computers really work at the system level, C is probably your choice.

I used to program in C++ butt switched back to C for it's simplicity and quite frankly certain beauty. I believe that C is way better for learning but that's my personal opinion. I also remember Eskil Steenberg saying something along these lines: C++ allows you to do sophisticated stuff easily so you start thinking you're really smart while in fact you're still quite dumb.

1

u/Computer-Nerd_ 15d ago

Start with C, there are better ways to learn object-based programming than a one-off attempt to shoehorn OO into C.

1

u/GuruPentameter 15d ago

master c first. this will make you, rather than someone else who thinks they might be, the master of choosing your next language to learn. you will be able to look at c++ yourself and say,

"hmm. yes, object orientation makes a lot of sense to me as a way of extending structs, i should learn c++.",
or
"classes, objects? a jedi of c craves not these things."

1

u/binarycow 15d ago

Keep going. If you want, you can learn C++ too.

Its fairly easy to learn a new programming language, especially if it's in the same "family" as one you already know.

1

u/Saw_U_Today 15d ago

Lol i was doing MBBS but my friend said MBBS is hard so now i am switched to CA 😄

1

u/TheFlamingLemon 15d ago

You should start with C, otherwise you may become one of those C++ programmers that doesn’t understand that when they pass a variable of a custom type as a parameter it creates a copy of the entire type and uses all your stack

1

u/MetalInMyVeins111 15d ago edited 15d ago

I love C++. But trust me, the state of this language has been utter crap for quite some time. Instead of fixing decade old problems in the language, they just keep dumping shitton of features in the standard that no one needs. Even Bjarne said something like he doesn't know all of C++. What's even the point of a language that you cannot realistically fully learn? Person A would use feature X and person B would use feature Y. And if they work together, there would be a good chance that person A would be seeing feature Y for the first time in his life and vice versa.

1

u/Chris_The_Mad_Guy 15d ago

Es como preguntar Si es mejor un coche o un auto

1

u/OutrageousCrab9224 15d ago

No

They are different treat them that way. Id focus on one till you feel at least solid, then you can focus on another

Of course we all learn differently but i am better off with more focus

1

u/thecratedigger_25 15d ago

C syntax fits on a sheet of paper. C99 is one of the most common versions of C since many low level apis are built on it.

C++ can be written like C code with a few extra rules added to it. I've seen codebases do it that way. But to avoid overwhelming yourself, stick to C99 and learn what pointers and indices do. Those 2 things power a lot of stuff.

1

u/HalifaxRoad 15d ago

Stick with C for now. Or forever... C++ has like 10 ways to do everything, and most of them suck.

Even classes, you can achieve this functionality in C by making a struct to store all the stuff your would be class needs. Then you can declare as many instances of the struct as you need, and pass them to your library as a pointer.

1

u/dividends4life 15d ago

Once you learn one, the others are easy to pick up. I am old so I prefer c to c++. LOL

1

u/gnix0 15d ago

Nope. C is absolutely a gem for learning foundational concepts in both programming and comp sci subjects. You can always (and eventually will) learn more languages. But sticking to one in the beginning is helpful and reduces friction in the process

1

u/ern0plus4 15d ago

If you forget C because of learning C++, don't switch.

You should try Rust, anyway.

1

u/free2dreamstudios 15d ago

Be using c and c++ your basiclly following the ssme path as windows

1

u/zasedok 15d ago

There is no point in switching to a different language just because a friend recommends it. Programming languages have huge cult followings and many people see using their pet language as an end in itself. Of course that's bollocks. Use whichever language helps you achieve objective benefits in the context of your project, as in, to develop a piece software that will be faster, more secure, easier to use, easier to maintain etc. Depending on what you set out to build, C++ could very well be the right choice. Or it could be C. Or it could Rust, or Go, or C#...

A programming language is only ever a means to an end.

1

u/Terwall 14d ago

C++ is just C with classes

1

u/Jeremi360 14d ago

C++ is the worst stdlib and syntax,
C++ can be good but if you use it with cstdlib instead of C++ stdlib

1

u/Tony1Rice 14d ago

Continue with C to learn control structures, data structures, memory handling, etc etc - as you are already doing. Make sure you get a -really- good handle on C without the distractions of classes and inheritance and all that other bullshot that C++ ads into the mix.

Then move on to C++ if you want/need to.

1

u/lucyuktv 14d ago

C++ possibly had more opportunities before AI came along. I suspect C will be more useful for a career now as embedded will be harder for AI due to hardware interactions.
Or learn plumbing. AI will never be a good plumber.

1

u/chrismw12 14d ago

If you're learning programming basics like variable types, function declarations, flow of control, C is a good choice. C++ adds more abstract concepts to scope things, but trying to figure out classes and inheritance wouldn't be very useful when you're not experienced with a while loop, for example. I would actually recommend starting at the assembly level, learning about cpu, registers, memory, and then C is the next logical choice as it was created as one-level up abstraction of assembly. I won't say it's necessary to learn assembly first, but if you don't want your higher-level language to be "magic" that's the best way I can think of: first learn what the cpu is doing when it executes a program.

1

u/cdtrmnbaell 13d ago

Do not jump directly into new language, you should do some projects with c so you can see how the really c is impressive. Start with small project , search about beginner project in c at github . Good luck

1

u/johndcochran 13d ago

Stick with C. As for reason why, perform a little research and see why the Linux Kernel is written in C, a little Assembly, and recently Rust. C++ was considered and excluded from its very inception.

Basically, C++ adds on top of C and has a lot of hidden machinery under the covers.

1

u/CERIBES 12d ago

I suggest sticking with C to build a solid understanding of programming, but also learning some Assembly. It helps you understand what's actually happening at the hardware level when your code runs. It is also valuable in software security, particularly reverse engineering, vulnerability analysis and understanding how exploits work.

Once your comfortable with both C and Assembly, learning other programming languages becomes much easier, as you'll have a solid understanding of what's happening under the hood.

1

u/kisamoon85 12d ago

stick with C for now, it really helps you understand how things actually work under the hood before moving on to c++

1

u/amosbatto 11d ago

It is good to learn C and C++, because they teach you a lot about programming and how computers work. I haven't written a C program in over 20 years, but I'm still grateful that I learned these languages. C was my first language, and starting there it made all the subsequent languages easier to learn, because I had a better idea how they worked under the hood.

However, I have to say after learning Rust, that I never want to go back to a memory unsafe language.

1

u/JustNomalboy 11d ago

Your opinion. but saying C have less opportunities is bit misleading. Correct me if I am wrong 🤗. Honestly, if you really want the control of c with abstractions of cpp, try Rust. It is memory safe by default. PS. I don't think cpp is a bad language but the stakes to making a reliable system with accurate control is very high.

1

u/mkhanwrites_ 10d ago

I'd stick with C tbh. You can learn C++ and modern OOP programming later.

0

u/wayzata20 15d ago

it’s fine to start learning in C. If you want a job writing C though, it’s going to be tough.

0

u/mckenzie_keith 15d ago

Ask in a C++ forum.

0

u/That-Drink5946 15d ago edited 15d ago

NO! DEAR GOD, DON'T DO IT!

Honestly. I would never even recommend a language to anyone these days, and C++ is possibly the worst right now as it drops you into a domain that is anything but fun.

Learning a language is more than learning a language, when you are looking at C++ jobs people expects you to know C++, that is not the issue, but then you need to know specific areas as well. This means you also need to do a lot of studying of Algorithms & math, applied to whatever field you're interested in.

And today. All of that shit, is done by LLMs which always will be better than you at this. So where are you going with this? What is it you're trying to do?

Just to be clear, this is how it works today:

You develop a program with Claude, it gets released. People find bugs or their program crash and deliver an automated bug report to you. This is awesome for your company because nowadays we have free QA people, they are called customers.

Because you or your company have already setup a completely automated bug fixing tool. When a mail or a bug report comes in, you have an LLM read the mail or analyze that report and classify it.

Then if it is a real bug or a real feature request that makes sense (based on the rules given to Claude) your AI acts on it and fixes the bug(s) / adds the feature(s). Updates the changelog, and releases / deploys the updated version.

This is why Microsoft or Facebook or Amazon etc, can fire all those programmers. This cycle works. And it works really well nowadays, it really did not before.

So the question that follows is this: Where do you see yourself here?

I know, it's tough.

-1

u/yyebbcyi 15d ago

Go for rust

0

u/[deleted] 15d ago

[removed] — view removed comment

1

u/yyebbcyi 14d ago

If you haven’t heard of rust yet then you better stick with C and build more things before you move anywhere else. Facts.

0

u/LionR6s 15d ago

Learn C. And eventually you will find rust. Don't even think about C++

0

u/[deleted] 12d ago

Don't need to switch just continue with C, and then "learn" c++, its not like anything you learned is wasted. Its not like going from c to rust and be completely confused by everything. 

Learn foundation and then you are much better at picking what part of c++ is useful and works for you

4

u/darkzima 15d ago

As a person who thought I needed to learn C++ my university used C instead. My professor always said “C is like a loaded gun. It will allow you to shoot yourself in the foot.”

For someone learning the basics C is a beautiful tool to teach you the basics and then more advanced topics like memory allocation, writing function definitions and even compiling your own static and dynamic libraries. You can even pick up Makefiles.

If you’re already on C stay there for now until you personally have a valid reason to switch. At the end of the day these are just tools, it’s the concepts that are critical here.