SuperMiguel said:
So i have read about 2 books about c, currentlybtaking a c class but I am 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 without 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 I am completelly lost
How did you guys learn this second part of c? Is practice practice practice the real solution?
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.