How to really learn c? Comp sci student

  • Thread starter Thread starter SuperMiguel
  • Start date Start date
  • Tags Tags
    comp sci Student
AI Thread Summary
Learning C can be challenging, especially when transitioning from basic concepts to more complex topics like pointers, structs, and loops. A strong understanding of memory structure and how pointers function is crucial. Practicing coding is essential, but it's equally important to grasp the underlying concepts. Visualizing memory addresses and flow control can aid comprehension. Engaging with textbooks, online tutorials, and practical coding exercises can reinforce learning. Additionally, exploring related subjects, such as assembly language, may provide deeper insights into how C operates at a lower level. Overall, consistent practice combined with a solid understanding of foundational concepts is key to mastering C programming.
SuperMiguel
Messages
109
Reaction score
0
How to really learn c? Comp sci student

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?
 
Physics news on Phys.org


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?
 


SuperMiguel said:
Is practice practice practice the real solution?

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 sort of 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.
 


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.
 


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.
 


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.
 


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


chiro said:
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:

http://www.cprogramming.com/

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.
 


bigfooted said:
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.
 
  • #10


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.
 
  • #11


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.
 
  • #12


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.
 
  • #13


RoshanBBQ said:
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).
 
  • #14


Jackx said:
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.

They're about as difficult to understand as understanding how an address can direct mail to your house.
 

Similar threads

Back
Top