r/cprogramming 2d ago

How to learn

I just started learning C about 5–6 days ago, and I had never coded before.

I completed the CS50 course, so I know the important concepts and have a basic understanding of how things work. But when it comes to actually implementing them, I feel like I’m at zero.

Now I’ve started learning C from the book The C Programming Language. I’m understanding some concepts, but not everything. I’d say I’m only understanding around 20–25% of what I read.

For example, I understand how "getchar()" and "putchar()" work individually, but when I see a program that uses them together, I don’t even understand 60–70% of the program.

I’m getting stuck, and it’s making me think that maybe only people with good logic can survive in programming jobs.

So, please guide me on how I should approach learning C correctly and develop my programming logic.

0 Upvotes

20 comments sorted by

6

u/torsten_dev 2d ago

You're on the right track.

Perhaps invest a little time to learn a debugger and step through the working code, or read up a little more on "control flow".

3

u/Straight_Coffee2028 2d ago

Take a pen and paper and write whatever you think the program is doing, what you think the output will be, do everything step by step and then compare it with the actual output. In early stages of learning programming, the more low-level knowledge you have of the computer architecture, the better. Once you get some confidence. Learn a debugger. GBD is a great one for beginners. Write down the expected output step by step on paper and compare it with GDB output. That is the only logical way to learn programming in general, Break things to the most fundamental level and build it up again

3

u/knouqs 2d ago

Five days into C and you are beating yourself up on it? No no no... this is something that takes months to acquire and years to master. Slow down. You picked the right book.

2

u/Illustrious-Cat8222 2d ago

Ditto. Also helpful is to write small throwaway programs that try out different language/library features.

You are doing really well for only 5 days on your first programming language. Just keep working at it; it'll all sink in.

2

u/Specific-Housing905 2d ago

Good logic is essential in programming, but it is a skill that can be learned.
Did you do the exercises in the book ? What were your problems?

2

u/Intelligent-War5714 2d ago

Studying+ doing exercises

2

u/greebo42 2d ago

Five-six days. Never coded before.

Completed CS50 course - that's a lot of video hours, so let's suppose you watched it once thru, and it made sense (yes, David Malan is a helluva teacher). That probably takes up most of the time frame you cited.

Now starting to read K&R. True story: I tried that. It's a great book, but it is terse. I dunno about you, but I remember getting blown out of the water in chapter 5 (pointers). I didn't have access to a compiler (this was, ahem, long ago). So I was just trying to learn the language by reading the book. After all, I already knew Fortan and Basic, and had even done some assembly by that time, so why not? Uhhh ...

So I think the answer to your question boils down to: (1) Rome wasn't built in a day, and a week is not a realistic time frame to expect to gain mastery, so don't be too hard on yourself. and (2) You can't learn to program by just reading and watching videos. You have to write programs. Small ones. Itty bitty ones. Build.

First things first. A couple years ago, when I decided to return to C after a long absence, it took me a few days to even figure out how to get a compiler to work and get Hello World to run. So start with that.

Maybe a sensible approach would be to try the assignments in CS50, starting from the earlier ones, build them a little at a time. If it takes Harvard students a whole semester to get thru it, it's probably a message that most of us mortals ain't gonna do it much faster than that.

If you're for real, try this. If this is a troll post (or AI), then consider me nerd-sniped and oh well. Perhaps some other C-curious person will stumble across this and benefit.

1

u/Intelligent-War5714 2d ago

Should I not study this book now?.. or again start from zero

1

u/greebo42 2d ago

The book is an excellent reference. The way you study is by writing code. You make some kind of program, get it to work, then ask yourself what happens if you change this or that, make mistakes, make breakthroughs, etc. Definitely want to have the book by your keyboard as you're grinding thru this.

1

u/Cyclotramp 2d ago

You’re taking the piss, you can’t finish cs50 in 5 or 6 days. If you are serious, you need to take a step back and learn the concepts the course thought you. Only when you understand that and know your weaknesses you can develop.

1

u/Intelligent-War5714 2d ago

So how much time I should give to learn this language I'm learning this language for build foundation and yk learning this language is nothing will be happen and that thing ik I'm just want to learn because this is in my semester and I heard c is the basic language by this i can build strong foundation... I don't know anything about how to learn how to apply..

2

u/Cyclotramp 2d ago

Sorry for being a bit harsh before. I think you should go back to cs 50 and learn each individual concept, regardless of the language they teach you that week. You need to internalize these concepts, like you really need to understand it so deeply that there are no questions left. They are teaching you the basics and how to to think like a programmer. It’s an excellent course for beginners and by the end of it you should be able to work on your own. My advice is to just keep asking questions till you are confident that you really know the concepts, you should be able to explain the concept to other people.

1

u/Intelligent-War5714 2d ago

Thanks buddy 🫂

1

u/ThePenguinMan111 2d ago

What I found works best for me when I was learning in the beginning is to make a program that isn’t just a little exercise. For example, making a demo program to print something to the screen, allocate memory, or whatever, is helpful, but making a program do something a level above that is where I found programming concepts to “click” more.

Instead of working on little exercises for the sake of completing the exercise itself, make a small program with a dedicated, real purpose. For example, my first little program was a roulette simulator, where a user could place bets and a random number would get picked to represent the pocket in the wheel. Since I had a goal that was a level of abstraction higher than the C code itself, it made me think deeper on what techniques I should be applying and how I could tailor them for my specific purposes.

1

u/bateman34 1d ago

You completed CS50 in 5 days? Did you do all the problem sets? How much help were you getting from AI? I was able to start writing simple games in C after finishing cs50 but it took me way more than 5 days to complete.

1

u/Intelligent-War5714 1d ago

Actually I was wrong .. i just watch video know some concept see how they work move to next video Guide me buddy how to do .??

1

u/bateman34 1d ago

You need to go to the cs50x website to find the problem sets: https://cs50.harvard.edu/x/ I recommend watching the sections before doing each problem set.

1

u/_tiev 1d ago

me too I'm actually in the same situation so .....lowkey reading the comments

1

u/Pale_Height_1251 1d ago

You've been doing it for 5 days, which rounds down to zero days.

You haven't started yet.

It's like learning to play golf, getting lost on the way to the course and thinking you're not cut out for golf.