1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to really learn c? Comp sci student

  1. Apr 5, 2012 #1
    How to really learn c??? Comp sci student

    So i have read about 2 books about c, currentlybtaking a c class but im having a bit of a learning issue

    When the class first stared it was very easy, i got everything and was able to do all book excersices with out problem, printf, scanf, ifs, for, do, all that was pretty easy. Then mid semester came in harder loops, struts, pointers, etc stared to appear and all the sudden im completelly lost

    How did you guys learn this second part of c??? Is practice practice practice the real solution?????
  2. jcsd
  3. Apr 5, 2012 #2
    Re: How to really learn c??? Comp sci student

    For me, seeing how a particular piece of syntactic sugar is used to make programming something easier was always the last step to solidifying my understanding. I guess that is one major benefit of practice. What is it that you don't understand?
  4. Apr 5, 2012 #3


    User Avatar

    Re: How to really learn c??? Comp sci student

    yes. (but not enough, if you're missing basic concepts. you may need to get help from someone like the prof or a tutor who knows C well.)

    C is a "high-level language" in that it isn't assembly, but it isn't a very high level language. C is not very abstract, compared to an object-oriented language like C++.

    if you're computer science, you really need to understand what pointers really are. you need to understand how a typical computer is structured in terms of memory, addresses in memory, and the contents at each address are. then (i think) you'll get pointers.

    structs are sorta like an array, but there are different types of things in a struct and structs can contain more structs. you need to understand what they are and how to use them.

    and you need to understand typedef also.
  5. Apr 5, 2012 #4
    Re: How to really learn c??? Comp sci student

    I learned coding by reading a textbook on the topic. I never could mesh with any online sources I found, and more than any subject, I truly believe coding cannot be taught in lecture.

    If you are not reading every page in your textbook, that is a start. If you are, maybe you need to find a better book. For c++, accelerated c++ is really good. I'm not sure about C.
  6. Apr 5, 2012 #5
    Re: How to really learn c??? Comp sci student

    I think structs, pointers and data structures are different concepts, which are of language type and control flow instead of simple IO and control structures.

    You have learned variables, later you need to wrap them up, you therefore need structs; In order to access the structs' internals, you need pointers or references. Besides, a reference is used as an alias to a particular object content; a pointer is a more direct way to retrieve the object content via memory access.
  7. Apr 5, 2012 #6


    User Avatar
    Science Advisor

    Re: How to really learn c??? Comp sci student

    Hey SuperMiguel.

    If you want to understand code think in terms of state and flow-control and realize that although they are related, they are also separated.

    When you look at code, think about the flow-control in terms of how execution occurs for the actual platform. If it's a standard PC architecture then this will be a lot easier to learn because things basically go in an instruction based manner from top to bottom unless you have things like function calls, loops, conditional jumps (if statements), unconditional jumps or other multi-threaded, multi-process or interrupt mechanisms.

    Just so you know you will not be dealing with the multi-threaded or multi-process or interrupt issue: you are only dealing with the idea that instructions go from top to bottom taking into account loops, if statements and function calls.

    If you need to, get a piece of paper and write down the flow control with arrows. This will make it a lot easier for you to see what is going on. Simulate the code on paper and use that intuition to understand later examples.

    The other thing is state. If you can keep the state of the program in your head, you will never have a problem not only writing code and reading code, but also debugging code which is the thing that 'forces' you to end up doing this.

    Take note of the variables, where they get read, where they are changed and build a map of that in your head. Start small with small programs and do it gradually: you don't have to do the complex things right away: build up your intuition slowly and steadily.

    In terms of structures and pointers, this is all about understanding what data is represented in terms of memory. Memory is just a sequence of bytes and that is how you should think of structures. Pointers are just a word-size that 'points' to a memory location. Pointers on 32-bit systems take up four bytes while 64-bit pointers take up 8. Just find out how many bits each data type takes up (int, float, double, long, etc) and then look at the structure in terms of that. Again do it slowly: first look at simple structures, then look at cases like classes where you get inheritance and take it from there.

    If you keep the above in mind while practicing, I think you'll get the hang of it soon enough. If you have a specific question ask in the Computer Science forums and someone will most likely answer it within a short time frame. Also provide code and any working and what is going on in your head so that we can give decent help.
  8. Apr 5, 2012 #7
    Re: How to really learn c??? Comp sci student

    My advice: think of a moderately complicated computer program that you could write, maybe something that is solving a common problem from another course, like a differential equation, or a linear algebra problem. It is a good exercise to learn c as well as 'the topic of the other course'.
  9. Apr 5, 2012 #8
    Re: How to really learn c??? Comp sci student

    Yeah. I think if you post a small piece and tell us what you don't understand about it, it might illuminate some issues perhaps with more fundamental concepts. If not, then someone can explain it to you! Practice is very important, but it doesn't help if you're not understanding the underlying concepts.

    I programmed for 7 years without reading a single book. All I did was get sample code from the internet and google small functions and expressions I didn't understand, and read tutorials on how to build certain scripts. There are numerous tutorials out there on how to learn languages. Here is a good one:


    Just go through the tutorials. They are much more straightforward than the textbook, and you can use the textbook to get to the nitty gritty detail (that you do have to know, by the way, to be a good programmer) after you have a good general understanding of the concept.
  10. Apr 5, 2012 #9
    Re: How to really learn c??? Comp sci student

    That's like an obese person exercising by joining a game of basketball in the NBA. I don't see what this could possibly achieve if he is having difficulty understanding pointers.
  11. Apr 5, 2012 #10
    Re: How to really learn c??? Comp sci student

    When learning C, I often wrote the code out and used comments as my basis to understand and talk to myself within the code. That really help to conceptualize what I was doing whilst remembering the specific nature of code and helping get the more harder loops down the line. But it seems you haven't mastered the basics well enough if you are completely lost.

    I rarely read the C book assigned and used a method similar to hadsed to learn C.
  12. Apr 5, 2012 #11
    Re: How to really learn c??? Comp sci student

    It won't really help you in the short term, but I found that when I took a course on assembly language and basic processor design, things like pointers and arrays suddenly made a lot more sense to me. Something about seeing exactly how you go from C-code to strings of ones and zeros that a processor can use really solidified my understanding. If you can take a course in assembly language, I'd definitely advise it, even if you don't have to. Assembly language is *horrible* to work with (which is why we have languages like C), but it really helps in understanding.

    Of course, if your issue is in implementation rather than in understanding, practice is definitely the way to go.
  13. Apr 5, 2012 #12
    Re: How to really learn c??? Comp sci student

    Pointers are difficult to understand and use. This is why in a lot of other languages they left them out or kept in the background.

    My advice is to try to make it visual. Draw boxes of each memory address you are working with and use pointers to point to these boxes.

    It's a difficult topic, or at least I found it so.
  14. Apr 6, 2012 #13
    Re: How to really learn c??? Comp sci student

    If you're taking a course on it, and you're a CS student, I think maybe chances are that you're not morbidly obese. That said, there are certain personality types for which this works really, really well. If that doesn't come naturally, it's good to build towards it. Often times in the real world, you're given a problem and it isn't clear how to proceed. No one is going to tell you the steps on how to solve things, so you just have to try a million things until you start getting somewhere, then keep plugging away at that. In the process, you learn a ridiculous amount more than maybe was required, but of course there is never anything wrong with learning more (and it's very likely that this acquired knowledge will help you in the future).
  15. Apr 7, 2012 #14
    Re: How to really learn c??? Comp sci student

    They're about as difficult to understand as understanding how an address can direct mail to your house.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook