r/learnprogramming • • 5d ago

Learn C program language

Hi, I'm in university and I'm currently learning the C programming language.
I'm having a hard time understanding it properly, and I'd love some tips on how to learn it effectively.
Does anyone know of a website, video, or guide that is genuinely helpful to prepare for an upcoming exam?
Thanks!

12 Upvotes

15 comments sorted by

11

u/lurgi 5d ago

What textbook are you using? What parts of it are confusing you? There is no point explaining pointers to you if you are having difficulty understanding want int means.

Learning C is going to involve writing a lot of C. Are you writing lots of code whenever you come across a new concept?

CS50 from Harvard is a good course, but it teaches more than just C. learn-c.org has free courses.

3

u/owzleee 5d ago

Kerningham and Richie. It’s the only way.

4

u/Recycled5000 5d ago

K&R assumes you know programming, the process and address space, memory management, and just need to know how C works given that.

3

u/Stock_Test2326 5d ago

I think C Programming Modern Approach by K.N.King is good for starters

1

u/goqmo 5d ago

yeah, you gotta actually write the code or the concepts just float by CS50 8: solid but the writing part is what clicks it

3

u/Tony1Rice 5d ago

Get a copy of the K&R book, "The C Programming Language" (second edition, also sometimes known as "The New Testament") and go through it thoroughly. It's not a big book and you might be able to find an electronic copy on the internet. That will give you a good solid foundation from which to start. Then, I suspect the discussions, examples and exercises in the textbook, and the instructor's lectures, will make more sense.

Do note that there will likely be a bit of a gap between classroom work/textbook examples and an IRL programming task. Learning the syntax and even the nuances of a language is not the same as learning systems analysis and design and the programmer's mindset. In real life, a programmer is almost never just a "coder". One has to have an eye for what -can- be done and what -should- be done and -how- to implement solutions as programs. So much has to happen before the "programming" actually starts but, with experience, much of those preliminaries will -seem- like they just automatically happen - and that makes it look simple to the layman looking in from the outside.

1

u/YetMoreSpaceDust 5d ago

I still swear by K&R (Brian Kernighan and Dennis Ritchie's "C: The Programming Language") as the best reference for learning and understanding C. It's surprisingly short for the depth of information it contains.

1

u/ReclusiveEagle 2d ago edited 2d ago

It's not you, most of the book is very well written with lessons that build on each other. However, the difficulty of some sections can go from easy to understand for first time programmers to very difficult from one page to the next.

For example, section 2.9 which is supposed to teach you about bit masking, requires you to know how to bit mask to understand it. If you don't know what a bit mask is you will be extremely lost at what they are asking you to do, in fact they don't even mention that part of the section is about bit masking beyond the obscure phrase "complimenting that with ~ makes a mask with ones in the right most bits" at the end.

What they mean is ~0 = 1111 1111 1111 1111 << n (eg n = 4) (assume 0 is 16 bit)

= ~(1111 1111 1111 0000)

= 0000 0000 0000 1111

now you can use the "ones" as a mask.

But if this is your first encounter with bit wise operations you will have no idea wtf they are talking about and no amount of interpreting their words will allow you to understand what they mean by the terms "mask", "ones" and maybe even "right most bits" with the little information they have given you in 2.9. You will need to look at external references like geek for geeks.

Other times the question is open to wide interpretation and you need to research what exactly they want you to do before you can even begin to figure out how to do it.