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?????

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?

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.

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.

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?????

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.

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'.

Also provide code and any working and what is going on in your head so that we can give decent help.

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.

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'.

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.

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.

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.

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.

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).