Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How difficult is it to learn C by yourself?

  1. Apr 19, 2010 #1
    I have absolutely no experience at all with computer programming or computer science. I was told by my buddy who is a computer programmer that I would probably enjoy learning C with the background that I have. He said it will be difficult at first, but with practice, I should be able to pick it up. I feel like learning a language would vastly improve my resume also for employment. I won't just be trying to learn C just to improve my resume, I have a genuine interest in learning C out of curiosity. Any recommendations on books that I should pick up?
     
    Last edited: Apr 19, 2010
  2. jcsd
  3. Apr 19, 2010 #2
    I recommend starting with matlab. Its not quite C but it's C based and very very easy to learn. It took me about 2 hours to pick up.
     
  4. Apr 19, 2010 #3

    Mark44

    Staff: Mentor

    What's the background that you have? Some backgrounds make it easier to learn C, and some not so.

    I would NOT recommend starting with matlab. matlab and C have very little in common as far as I can see.

    Since you have no programming background at all, it might be very difficult to learn C on your own. You could probably learn enough to write simple programs, but picking up the fine points about arrays, pointers, and other nontrivial features would be difficult.

    What about taking a class? Lots of community colleges have classes that would help you get started, with many offerings at night.

    If taking a class isn't an option, there are quite a few books out there. Herb Schildt has written quite a few that would be helpful. It's also good to have a reference book or two around, such as The C Programming Language, by Kernighan and Richie. These two guys designed the language, so they are certainly experts in it. Another one that I would recommend as a reference is a book whose title I don't remember, but the authors are Hardison and Steele. That's an excellent reference also.
     
  5. Apr 19, 2010 #4
    Lots of people learn C/C++ on their own -- there are tons of nice books for it. Just stop by the library/bookstore and find something one that looks good to you. Since you are learning on your own, pick a book one that looks super easy, has lots of examples, etc.

    Have your buddy show you how to compile your code, use an editor/debugger, and all of that kind of stuff.

    Btw, I'd recommend you start with C++ or Java, as opposed to say C or Fortran.
     
  6. Apr 19, 2010 #5
    I have a degree in mathematics, so my friend that is a programmer said I would probably enjoy learning C. I would like to learn both C and C++. Should I learn one before the other? I really don't feel like spending a lot of money on a class for something that I could learn on my own.
     
  7. Apr 19, 2010 #6

    Mark44

    Staff: Mentor

    I guess I would recommend C first, since C is a much simpler language.
     
  8. Apr 19, 2010 #7

    DaveC426913

    User Avatar
    Gold Member

    From scratch? With no prior programming experience at all?
     
  9. Apr 19, 2010 #8
    Try not to learn the whole language at once. Make small test programs like "hello world" to get the basics down then explore the more complex ideas like structures, pointers and dynamic memory.
     
  10. Apr 19, 2010 #9
    Yeah, that's how most people I know did it (myself included). Just make sure that for your first book you get something in the ballpark of "C++ for Dummies", "Teach yourself in 24 hours", etc. -- not something technical.

    Mark44 is probably right, C might be a better choice for the first language. They are very similar though, and learning OO programming is never a bad thing, so either way I don't think you will go wrong. Just jump in head first, and don't be afraid to ask your buddy questions.
     
  11. Apr 19, 2010 #10

    DaveC426913

    User Avatar
    Gold Member

    Not BASIC or FORTRAN or JavaScript first?

    You first encounter with an IF statement was in C/C++?
     
  12. Apr 19, 2010 #11
    Yeah and honestly the IF was a lot easier than being told to do it in linux and explicitly to use vi (in a classical mechanics class no less, calculating the projection of a baseball with velocity dependent air resistance -- won't forget that assignment...). But hopefully his friend will spare him those details this first go round.

    At the basic level (IF/FOR/x=a+b,print,...) all the languages are about the same, so it doesn't matter what he learns first, he will see the same stuff.
     
  13. Apr 19, 2010 #12

    DaveC426913

    User Avatar
    Gold Member

    That was kind of my point.

    My presumption has been that you had been exposed to the basics of programming (such as IF statements) before you started learning C.

    But someone with no exposure even to those basics is going to find C quite daunting.

    However, I will take you at your word. If you say you first encountered an IF statement when learning C, then you first encountered an IF statement when learning C.
     
  14. Apr 19, 2010 #13

    rcgldr

    User Avatar
    Homework Helper

    Other than us old timers that first encountered IF statements in Fortran IV, I would assume most programmers less than 40 years old first encountered IF statements when learning C (or Pascal, not sure when it's popularity faded).

    Assembly language with an inteactive debugger would also be nice to learn, but's it relatively rare these days.
     
  15. Apr 19, 2010 #14
    I learned to program this way as well. Unless you are a professional programmer or computer scientist learning a programming language or just how to program in general isn't that hard. I once did take a class that involved programming in ABEL but that didn't really teach programming just how many ways someone can commit suicide.

    Anyway, any decent programming self help book will have you coding simple programs in a couple hours. I personally would start with C++ or VB if you are interested in programming stuff for PCs and C if you are programming embedded electronics. And of course I have to again recommend Matlab as it's the best scientific computing language there is.
     
  16. Apr 19, 2010 #15

    rcgldr

    User Avatar
    Homework Helper

    For the initial learning experience, creating dos console programs that input and output simple text (scanf, printf), will be much easier to learn than messing with Windows programming. In addition, a typical Windows C++ program has a lot of hidden stuff going on, which makes it easier to program, but complicates the learning process with all that pre-written hidden stuff.

    I don't know much about self-teaching books (primers) for C or programming in general. I used a primer for Fortran IV from IBM back in 1969, and things have changed quite a bit since then.

    The main thing is the initial programs you create while trying to learn a language. These will not be very useful, but they'll teach you the basics of programming.

    I posted a thread to a minimalist programming language with some challenging puzzles. There are few enough intructions that you can brute force solutions by trying every possible instruction, but still some actual programmers get stuck on the third and most difficult program.

    Link to just the first post of the thread, (no answers).

    https://www.physicsforums.com/showpost.php?p=1347155&postcount=1
     
  17. Apr 20, 2010 #16
    I've been programming for 30 years, since I was in high-school. Once you learn one language well it is easy to learn another one.

    C is a decent language but not the one I'd recommend for starting at this point. C depends heavily on pointers which are essentially references to memory addresses. Pointers are complicated and it is real easy to get things wrong in the beginning and cause yourself hard to track down crashes and bugs. These sorts of bugs are the source of most of the security vulnerabilities in software and operating systems.

    For most people, I think learning python would be much better. It is much easier to get things done without tripping yourself up.

    If you are stuck on learning C, then make sure you get a good programming environment with a visual debugger (generally known as an IDE for Integrated Development Environment). The best one I've ever used is Visual C++ (which also works for C) for Windows machines. XCode on the Mac is decent as well. A visual debugger will allow you to step through your programs line-by-line so you can see what the program is doing and catch any mistakes in logic more easily. It will allow you to verify your assumptions about what the program is doing.
     
  18. Apr 20, 2010 #17

    rcgldr

    User Avatar
    Homework Helper

    Pointers are more of an issue of the program to be written than the language. There's no reason for the initial learning experience with C to focus only programs that do not involve the usage of pointers.

    Initial programs could simply be based on integer or double precision variables, only using format strings with scanf and printf for input and output. This is not much different than the first few Fortran programs I wrote.

    The key here is a primer or other learning book that starts off with fairly simple programs, then advances with programs that utilize more of the features in a language over time.

    For a math major, the first program might be one that reads in two numbers (scanf), mutliplies them, and outputs the product (printf). The next program might read in two numbers and ouput which one is greater, using a single "if" statement. The next program might be one to solve a quadratic equation, inputting the 3 coefficients one at a time (3 calls to scanf), doing the math, then outputing the possible roots. This would require using an if statement and the sqrt() function.
     
    Last edited: Apr 20, 2010
  19. Apr 22, 2010 #18
    I'm a EE major CS minor. I took c programming this semester and I don't see any reason why you couldn't learn it on your own. My prior computer experience was nothing amazing and I didn't have much of a problem picking it up. As stated earlier you may have a little trouble when you get to pointers, arrays, structs, etc, but with a decent book and the internet (cplusplus.com = great reference) it shouldn't be a problem.

    At my school they actually teach C programming then Java.
     
  20. Apr 22, 2010 #19
    The issue here is really with the question of whether or not it's a good idea to have a general recommendation about the wisdom of learning C as a first programming language. Undoubtedly, there will be many people for whom C will prove difficult as a first language: typically these people will have no experience with programming languages whatsoever and will also have little or no experience thinking in the sort of rigidly structured, logical manner required by C. People like this would benefit greatly by first learning a more expressive and intuitive language such as Python before moving on to C.

    On the other hand, there will also be plenty of people who do have some experience thinking like a programmer. Generally speaking, there's no reason whatsoever why these people couldn't start with C as their first language. They may even benefit from early exposure to the relatively low-level nature of C.

    The key, therefore, is for people to identify the type of background and experience they possess before deciding which approach is best for them.
     
  21. Apr 22, 2010 #20

    rcgldr

    User Avatar
    Homework Helper

    My point was that the learning experience starts off using a very small and simple sub-set of C (or any language), then expands on the features of C (or any language) as part of the learning experience. I don't see Python having any advantages to C here.

    For the initial experience, an interactive environment might be better, something like classic basic, or simple calculator like language similar to C (the expression evaluator part) would be helpful.

    One hurder to overcome would be learning an IDE like Visual Studio. I assume someone has made a set of learning projects along with some tutorials based on Visual Studio or something similar.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook