How to really learn c? Comp sci student

In summary: When you are first starting out, it can be a little bit confusing to understand what a structure is and what it can do. A structure is basically a way to group together variables and also define what those variables can do. For example, you might have a structure called 'person' that contains information about a person's name, age, and address.Structure can also be used to define the way data is accessed. For example, you might have a structure called 'player' that contains information about who is playing a game. When you want to access the information about the player, you would use a reference to the player structure rather than just accessing the individual variables inside the player structure.So in summary, you
  • #1
SuperMiguel
110
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
  • #2


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?
 
  • #3


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


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


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


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


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'.
 
  • #8


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


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.
 

Related to How to really learn c? Comp sci student

1. How do I start learning C as a computer science student?

The best way to start learning C is by familiarizing yourself with its syntax and basic concepts. You can do this by reading books or online tutorials, and practicing coding examples. It's also helpful to have a good understanding of data structures and algorithms, as they are essential in C programming.

2. What resources should I use to learn C?

There are many resources available for learning C, such as books, online tutorials, and coding platforms. Some popular books include "The C Programming Language" by Kernighan and Ritchie, and "C Programming: A Modern Approach" by K.N. King. Online platforms like Codeacademy and Coursera also offer free C programming courses.

3. Is it important to practice coding in C?

Yes, practice is crucial for learning any programming language, including C. As you practice coding, you will become more familiar with the syntax and develop problem-solving skills. It's also a good idea to work on projects to apply your C knowledge and gain practical experience.

4. What are some common challenges when learning C?

Some common challenges when learning C include understanding pointers, managing memory, and debugging. Pointers can be tricky to understand at first, but it's important to grasp them as they are fundamental in C programming. Memory management can also be challenging, and it's essential to learn how to allocate and deallocate memory properly. Additionally, debugging can be time-consuming, but with practice, you will become more efficient in finding and fixing errors in your code.

5. How can I improve my C skills?

To improve your C skills, it's crucial to keep practicing and challenging yourself with more complex projects. You can also read books and articles, participate in online communities and forums, and collaborate with other programmers. Additionally, it's helpful to learn other programming languages as they can provide different perspectives and approaches to problem-solving.

Similar threads

  • STEM Academic Advising
Replies
2
Views
2K
  • STEM Academic Advising
Replies
4
Views
1K
  • STEM Academic Advising
Replies
1
Views
1K
  • STEM Academic Advising
Replies
1
Views
2K
Replies
9
Views
1K
Replies
2
Views
979
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • STEM Academic Advising
Replies
6
Views
3K
  • STEM Academic Advising
Replies
16
Views
1K
  • STEM Academic Advising
Replies
4
Views
4K
Back
Top