Thread: For someone New to C should I learn C or C++ ?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    10

    For someone New to C should I learn C or C++ ?

    For someone New to C should I learn C or C++ ?

    I’m sure this has been asked many times, hopefully
    I won’t get slammed to hard for asking it yet again…
    (I’ve even did a Google search and I’m no closer to a real answer.)


    I’m 46 and have used basic since I was a kid but mostly for my own personal
    projects. I’ve never had a true need for C so I never learned it. But it has
    always been my desire to do so (So I can say I know how to program).


    So for a guy in my position what would be the best language to learn?


    Thank you

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Which do you want to learn?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My guideline is this:
    - If you love to roll out your own solutions, don't like OOP, and don't like strict type systems, then go for C.
    - If you like to use existing algorithms and solutions, like OOP and like strict type systems, then go for C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    10
    Quote Originally Posted by laserlight View Post
    Which do you want to learn?
    The one that will be the most universal, as in I can write for
    everything from a microcontroller to a small desktop app.


    Quote Originally Posted by Elysia View Post
    My guideline is this:
    - If you love to roll out your own solutions, don't like OOP, and don't like strict type systems, then go for C.
    - If you like to use existing algorithms and solutions, like OOP and like strict type systems, then go for C++.
    I'm used to prety much building my projects from scratch, but that being said
    coming from Basic I'm not sure I even fully understand what OOP is all about.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by harry_y View Post
    The one that will be the most universal, as in I can write for
    everything from a microcontroller to a small desktop app.
    Microcontrollers (usually) use either C or C++.
    It depends on which microcontroller you want to program for.

    I'm used to prety much building my projects from scratch, but that being said
    coming from Basic I'm not sure I even fully understand what OOP is all about.
    It's not about fully understanding - it's about what you LIKE. Do you like OOP? Do you hate it? If you don't know what it is, or haven't experienced, then I might suggest you should.
    Knowing what paradigms you like or dislike will help you choose a better language.

    Otherwise, I might just suggest you start out learning both languages within reason. Not too much. Not too little. Then make up your mind about which you like best.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by harry_y View Post
    The one that will be the most universal, as in I can write for
    everything from a microcontroller to a small desktop app.
    Pretty sure anywhere you can use C++ you can use C, but this is not true the other way around.

    They are not totally divorced from one another. You can always start with C and later if there are elements of C++ that appeal to you (eg, OOP or templates) then you can learn that. Most of what makes C++ "what it is" are additions to C, and while some parts are intended as "replacements", you are free to ignore (or use) them as you please. There are very few genuine incompatibilities, you can use C code and libraries/APIs (usually) in C++ code.

    Once you understand C, it is not very hard to understand C++, and that probably is true the other way around. However, people who learn C++ and then need to deal with C sometimes express a lot of frustration with what Elysia calls "a lack of safeguards".

    Also, for the most part C syntax is fairly intuitive and logical, whereas C++ seems comparatively contrived and arcane. This is not necessary a bad thing, but it probably does mean that C is easier to learn.
    Last edited by MK27; 05-26-2010 at 01:05 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    It's no big deal to learn C first and then C++. In fact speaking as a novice myself I would recommend doing it in this order, because the C/C++ way of programming is so different to BASIC and learning C will introduce you to the basic ideas without overwhelming you of some of the complexity of C++ and OOP. The syntax of C is very easy to learn but you will quickly realize that some of the things you routinely do in BASIC actually take a lot more care and effort in C. But along the way you will become a lot more aware of what's going on in terms of memory and processing than you probably ever were with BASIC.

    In my opinion, learning C first gives you a head start when it comes to tackling the good C++ books and it will also open the door to a lot of online tutorials and video lectures. If you're going to be learning from books, I would heartily recommend "C Primer Plus" by Stephen Prata - if you get through the whole of this book and do all the exercises you're going to feel very confident. Then, when you feel like you understand C, there are two books which if you study in tandem with each other, will really help you understand C++. Firstly there is "Thinking in C++" by Bruce Eckel which is available free online. This book will teach you the mechanics of C++ in great detail from the ground up, but isn't so big on the practical aspect, but reading "Accelerated C++" by Koenig and Moo will fill in a lot of those gaps by teaching C++ from the top down. I thoroughly enjoyed all three of these books, they're the best programming manuals I've ever read.

    Also, when you have the basics of C down that will enable you to tackle the superb Stanford video lectures of Jerry Cain, which can be found on YouTube. I learned so much from these lectures it's unreal. This guy is one of the best teachers I've ever seen.
    Last edited by Sharke; 05-26-2010 at 01:08 PM.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    10
    Thank you...

    I've been looking at both and running throught the tutorials here trying to get
    a little feel for both. Elysia may have the best answer in that I should become
    a little more familiar with both before really focusing on one or the other.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    10
    Sharke, Thank you for the insight. Going throught the tutorials for C some
    of it is starting to click so maybe you can teach an old dog some new tricks.

    I will admit it is a a little intimidating coming from Basic, but then on the bright
    side I at least somewhat understand how things should flow in a program.


    Thank you Everyone!

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MK27 View Post
    Once you understand C, it is not very hard to understand C++, and that probably is true the other way around. However, people who learn C++ and then need to deal with C sometimes express a lot of frustration with what Elysia calls "a lack of safeguards".
    Quote Originally Posted by Sharke View Post
    It's no big deal to learn C first and then C++. In fact speaking as a novice myself I would recommend doing it in this order, because the C/C++ way of programming is so different to BASIC and learning C will introduce you to the basic ideas without overwhelming you of some of the complexity of C++ and OOP. The syntax of C is very easy to learn but you will quickly realize that some of the things you routinely do in BASIC actually take a lot more care and effort in C. But along the way you will become a lot more aware of what's going on in terms of memory and processing than you probably ever were with BASIC.
    Many would disagree, as do I. Learning C first and then learning C++ is a mistake. You learn a lot of bad habits you later have to unlearn when learning C++.
    In fact, since part of C++ is C, I would definitely recommend learning C++ first if you're intent on learning both languages.

    Quote Originally Posted by MK27 View Post
    Also, for the most part C syntax is fairly intuitive and logical, whereas C++ seems comparatively contrived and arcane. This is not necessary a bad thing, but it probably does mean that C is easier to learn.
    I doubt that. It may seem that way to someone who is used to C programming in the first place, but certainly not to newbies into the language. The fact of not having to deal with arrays, malloc, strings and whatnot makes it so much easier to learn C++ before C.
    Granted, there are some very difficult areas of C++ to master, such as templates, but full knowledge of them are hardly required to become a good C++ programmer.
    Wheras in C, you have to learn a lot of those tricky things to become a good C programmer.
    So I would definitely claim that this statement is wrong. It simply depends on the programmer itself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    10
    A lot of great insight (AKA Do I ever feel ignorant).

    I'll throw in a twist, I highly doubt I'll ever write something very large or complex.
    Most of what I've ever written has been for Microcontrollers or a small program
    to do a simple task. I'm not sure if that skews it one way or another.

    I guess I have a bit of reading ahead of me.

    Thank you again.

  12. #12
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I tend to favor the idea of starting with C++. Even if you don't use any of its OOP stuff.
    Then you have a choice. Continue on a more object oriented path or go to more lower level C path. At one point you might say "hmm, classes seem interesting, let me try them". I think at that point it would be better if were already programming in a C++ environment. Even when you look online, you will bump into more stuff when you are typing C++ rather than C, which might give you the incentive to learn them.

    As see that starting from C++ opens more doors. A recommended book would be a C++ one that is more analytical and covers C as well.

  13. #13
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    For MCUs, I would stick with C.

    Some MCU development environments have some support for C++, but almost none supports the standard library, which is arguably 80% of what C++ is all about, and what makes C++ "nice".

    None of the standard containers will work (including std::string), for example, since MCUs don't typically have a heap to begin with (heap management doesn't make sense when you have <1KB RAM).

    With that kind of resources constraint, you don't really want C++ overheads anyways.

    I've never seen anyone doing OOP on MCUs. OOP is designed to make large programs easier to design/maintain, but has limited use when you just want to blink a few LEDs.

    This is all assuming you are talking about 8-bit/16-bit MCUs. If you are talking about bigger 32-bit MCUs like those ARM based ones... I've never actually programmed one, but people have run Linux on them, so I'm assuming they are more similar to PCs in terms of typical program complexity.
    Last edited by cyberfish; 05-26-2010 at 09:34 PM.

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    I only have experience with 32 bit PIC MCUs, and they are programmed using C and assembly. So if thats all you will touch i would suggest go with C. However if you also want to dabble with desktop programming I would say C++ is a nice compliment. And you can (and will) learn alot of C-style programming with C++ aswell.

  15. #15
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    I wanted to program, so I learnt C for 9 months. C is a beautiful language. I loved it. But I could only use it for console and text-based programs. What I really wanted was to be able to create GUI programs that I could use in Windows. So I switched to Visual Basic, and that was the best move I ever made, programming wise.

    I had learnt C on and off for about 20 years, but each time I was couldn't get past the usability hurdle. For people who require C as part of their job or studies, they have motivation to persist with it. I am only a hobby programmer, so unless I could program what I want, in the environment that I want(Windows), there was no motivation.

    Once I master VB, I will get back into C. It can do low level stuff easily, which is not so easy in VB.

    Good luck.
    OS: Linux Mint 13(Maya) LTS 64 bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quickly learn C# for a C++ expert
    By BigDaddyDrew in forum C# Programming
    Replies: 9
    Last Post: 06-06-2004, 04:38 PM
  2. The best place to learn
    By CougarElite in forum C Programming
    Replies: 15
    Last Post: 04-25-2004, 04:07 PM
  3. Novice trying to learn C++
    By dead in forum C++ Programming
    Replies: 10
    Last Post: 12-01-2003, 09:25 PM
  4. Witch to learn first?
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 06-17-2002, 12:06 AM
  5. Learn Win32 API or C++Builder?
    By Flucas in forum Windows Programming
    Replies: 1
    Last Post: 10-18-2001, 01:49 AM