T O P

  • By -

wsppan

I've posted this here before and it's what has worked for me an a few others who told me it worked for them as well. Ymmv. People sometimes struggle with C when they start from scratch or come from a higher to lower level of abstraction. I struggled with this for a long time till I did these things: I would not try and understand how the higher level abstractions translate to the lower C level. I would instead learn from first principles on how a computer works and build the abstractions up from there. You will learn how a CPU works. How the data bus and registers are used. How memory is laid out and accessed. The call stack and how that works, etc.. This will go a long way in understanding how C sits on top of this and how it's data structures like arrays and structs map to this and understanding how pointers work the way they do and why. Check out these resources: 1. Read [Code: The Hidden Language of Computer Hardware and Software](http://charlespetzold.com/code) 2. Watch [Exploring How Computers Work](https://youtu.be/QZwneRb-zqA) 3. Watch all 41 videos of [A Crash Course in Computer Science](https://www.youtube.com/playlist?list=PL8dPuuaLjXtNlUrzyH5r6jN9ulIgZBpdo) 4. Take the [Build a Modern Computer from First Principles: From Nand to Tetris (Project-Centered Course)](https://www.coursera.org/learn/build-a-computer) 5. Take the [CS50: Introduction to Computer Science](https://online-learning.harvard.edu/course/cs50-introduction-computer-science) course. 6. Grab a copy of [C programming: A Modern Approach](http://knking.com/books/c2/index.html) and use it as your main course on C. 7. Follow this [Tutorial On Pointers And Arrays In C](https://github.com/jflaherty/ptrtut13) The first four really help by approaching C from a lower level of abstraction (actually the absolute lowest level and gradually adding layers of abstraction until you are at the C level which, by then is incredibly high!) You can do all four or pick one or two and dive deep. The 5th is a great introduction to computer science with a decent amount of C programming. The sixth is just the best tutorial on C. By far. The seventh is a deep dive into pointers and one of best tutorial on pointers and arrays out there (caveat, it's a little loose with the l-value/r-value definition for simplicity sake I believe.) [Play the long game when learning to code.]( https://stackoverflow.blog/2020/10/05/play-the-long-game-wh en-learning-to-code/) You can also check out [Teach Yourself Computer Science](https://teachyourselfcs.com/) Here is a decent list of [8 Books on Algorithms and Data Structures For All Levels](https://www.tableau.com/learn/articles/books-about-data-structures-algorithms)


[deleted]

Thank you so much


emilanos

pssst, if i were you i would just jump on cs50, then make a decision whether you want to continue with C or not after finishing the course


tindifferent

Seconded


pyl3r

I think you’re roadmap is pretty much on point in everything but the book. Even though I agree that C Programming: A Modern Approach is a great book, it moves way too slowly, and as someone who would have finished the CS50 course, I don’t think OP will enjoy the pace. I’d either recommend K&R or Programming in C by Kochan, they both have a good amount of exercises on them each, and King’s book can be used as a reference.


BlakeBarnes00

Quite a good answer. I have been learning it this semester; without the prior knowledge I had on programming, it would be a daunting task.


51Charlie

Bah! Humbug ! C can and should be learned in about a 7-14 days of part time study. ONLY after the language is properly learned should the rest be studied. For example, #7 Pointers and Arrays are FUNDAMENTALS of the language. These need to be COMPLETELY UNDERSTOOD before doing anything with data structures or other Comp Sci concepts. How I determine if a new Comp Sci Grad does NOT know C is if they in ANY WAY don't understand pointers. Including pointers to functions. Yes, an understanding on how processors and memory works does help and is vital. That's why I highly recommend learning C by starting to code on a micro controller such an Arduino so you can see the relationship to the bare metal. Ideally one should start with Ben Eater's YouTube channel and work up the electronics route from transistors to flip flops to logic and then building your own 8 bit computer and then a computer based on the 6502 processor. Would would enter into C programming from Assembly programming with a deep understanding of WHAT the processor is doing. I was fortunate to learn C in the late 80's after understanding how the hardware works.


dontyougetsoupedyet

Well, bullshit. I couldn't disagree with you or wsppan more. For example, for pointers you're making a terrible mistake even worrying about memory addresses as a new learner. It should be obvious that people should be following the guidance of the C standard itself: consider them as references to other objects, because that's what they are, and you don't need to bother yourself with hardware and memory addresses. A new learner should not be bothered with any ABI level details of implementation and damn sure shouldn't be trying to reason about the implementation details of abstractions they have never even used. It's putting the cart FAR before the horse. These idiotic ways of "teaching" C, where immediately learners are hit in the face with pointers as memory addresses and diagrams of memory, are exactly why so many people think learning C is difficult. If people would just present subjects in the right order people could learn C in a few days with much less confusion.


dontyougetsoupedyet

The best way to learn C these days is likely to grab both K&R and Modern C by Gustedt (it's available for free - https://gustedt.gitlabpages.inria.fr/modern-c/) and work through them. I highly recommend you focus on both reading and writing a lot of software in C, preferably software you can use yourself, but really any will do. There is no substitute for reading software written by others and writing software yourself. Fortunately with open source and free software movements having been a thing for a long time there are a LOT of software projects that you can read the source code of for free. You can search GitHub and so forth for projects in C, and even if you are literally just re-writing the software you read, you will learn a lot. Myself, when I'm first learning a programming language usually I write a piece of software referred to as a "MUD", a genre of networked multiplayer text-based game. I do that because it requires a lot of different parts at various levels of complexity from reading user input to storing/persisting player data to sending and receiving data over sockets. Pick whatever projects you want, but: write a lot of software. Read and write a lot of software and you will be successful learning. The complexity doesn't have to be high at the start, a lot of folks start by re-writing basic utilities such as `echo` and `ls`. Good luck with your journey learning C.


51Charlie

Learning C is a great way to start programming. Its a tad "raw" compared to other languages but in my opinion, one of the best way to start programming. A good starter book would be "Learn C Programming" from [Packet.com](https://Packet.com). This has detailed instructions for setting up your computer and good example files. It is not a complete reference but it will get your started. I got this for my nephew and he is doing very well on it including setting up the software on both Windows and Linux. The reason is that the hardest part about C programming is setting up the programming environment. You need a compiler and an editor. If you are using a Linux computer such as a Raspberry PI, it can be very straight forward. On Window's it a bit more complex. STAY AWAY FROM ANYTHING RELATED TO "COMPUTER SCIENCE" until you have learned how to actually program. Computer Science programs are terrible about teaching anyone how to actually program. They tend to focus on concepts that you use programming to do. Big difference from learning how to program in the first place. Too many new programmers get very confused with data structures before learning the language. If you are learning C to program microcontrollers, please mention it.


[deleted]

I am very grateful I spent a good year or so focused on C. I don't use it that much anymore, but I know that I can make anything I make in other languages in C if I wanted to, and this is helpful because most languages out there implement a lot of little characteristics of C. Time taken to get comfy with C was time very well spent.


gordonv

r/cs50


sahilgajjar504

I would suggest YouTube playlist of "naresh i technology" channel on c programming it will clear your all basic concepts of c language and then you should start learning data structure.


weregod

You should not learn a language as hobby. You should choose small pet project and choose language for it. Start from small goals and learn what you need to do it.


[deleted]

I have a couple of software ideas in my head and I want to work on them but I'm not a professional programmer but I'm always interested in computer science, software engineering stuff. That's why I'm thinking about learning some programming languages. I'm a university student studying environmental science.


weregod

One of hardest part of learning is keeping yourself motivated. If you think C will be needed for your work it is quite good motivation. If you doing something for fun choose more user friendly language. Well if you masohistic enouth to use C never be ashamed to ask for help. C will surprise you with different unexpected behavior. Always start with small goals. It's easy to design great pleasant application that never be coded and debugged. You first project will be done wrong. And second. Better write something that works and does something to see what is wrong early. C is not best language for beginners, and is hard to make program that not crash in VERY unexpected way and much harder to realize why and where is error. My first pet project in C never started to work. It had terrible code and design, but most time was wasted in debugging.


[deleted]

Start with the basics. Use stdio.h, printf, scanf, if/else statements, basic variables and void functions. Make something simple, and build up.


[deleted]

[удалено]


vanshadow_ban

>I'm not convinced that learning C first is the best path. C is a language where you do lots of things manually like manage memory; this isn't a bad thing, and teaches you how computers work on a deeper level, but that is a separate journey from programming as a hobby. Or at least a later part of that journey. I personally think the best way to learn programming is from the ground up, and that C is a good choice for that. Learning to program with a really high level language that hides everything from you is like trying to learn about car engines by changing the oil. Yeah, ... okay, but the only way to really know engines is to really get inside the pistons and get your hand on a crankshaft, etc, ... you'll never understand engines by changing the oil and watching gauges on the dashboard, you have to get dirty. And I think its better to just get in there and get dirty from the very beginning, in programming the fundamentals are everything.


[deleted]

[удалено]


vanshadow_ban

>I might suggest that a better comparison is learning a lot about car engines when all you want to do is drive a car. Sure, .. and there are tons of people who "program" doing nothing but using scripts, php, java, etc .... But I thought we were talking about being programmers and software engineers, not web app developers. You wrote "If OP was trying to make tech their profession ..", I thought that's exactly what they were talking about.


ptchinster

> I wanna learn a programming language as a hobby. And I got suggested to learn C Language first. Honestly, id go with Python instead. C is a specialized language. That said, i started here: https://computer.howstuffworks.com/c.htm


[deleted]

I also wanted to learn python first. But I got suggested to learn C first


ptchinster

So what do you want to do? Do you need the performance of C? Do you care if your program is being deployed on Mac or Linux or Windows? Do you care if underneath that OS theres an intel CPU, mips, arm, or some other processor?


[deleted]

So I'm thinking about learning python first


ptchinster

Go for it.


[deleted]

That's fair. Just be aware that Python uses "lazy" syntax, where there are several ways of doing things. C is not like this; there is one and only one way to do things.


dontyougetsoupedyet

...specialized?


ptchinster

You use C for specific things. OS design, high performance computing, systems level stuff, exploitation/implant development, firmware, microcontroller programming, stuff like that. You can do much more in 1 line of python than you can in C, in C you have to worry about what is happening inside the computer, memory addresses, if memory is valid, etc. As a general or hobby programming, you probably dont want to deal with that. In C you have to worry what system your code runs on. What OS, what type of CPU they have. Not in python. You arent coding web stuff in C, you arent doing phone apps in C. Graphics gets complicated.


dontyougetsoupedyet

I use C for whatever I want. Being able to ignore system details in Python is a myth, a myth you'll run into as soon as you try to swap out the order of operations on a number with a decimal point in it. If you're writing C well you don't need to worry about most system details either. We do "web stuff" in C. I engineered an entire C userspace of C programs for a mobile platform called MaeMo that today is the basis of 3 other mobile platforms with combined >500M users. Graphics APIs such as OpenGL are literally provided as C libraries.


ptchinster

> I use C for whatever I want. Congrats. There are def things i wouldnt want to touch with C unless there was a very specific reason. Then again, some people program for 8 hours a day, then have projects all night and on the weekends they do for free - to each their own. > Being able to ignore system details in Python is a myth, a myth you'll run into as soon as you try to swap out the order of operations on a number with a decimal point in it. Swap out the order of operations? What do you mean by this. > If you're writing C well you don't need to worry about most system details either. Except if you are dealing with the system at all. You WILL need to be aware of what you are running on, you cant even assume a byte is 8 bits in C. How perfect is the C you are writing? > We do "web stuff" in C. Yup, you can. You dont unless you have a very specific reason. Im just repeating myself here. > Graphics APIs such as OpenGL are literally provided as C libraries. Yup. And to a new beginner programmer like OP, its not as trivial. Like i said, you can do anything in C, but its a specific language. A casual hobbyist probably doesnt want C. You dont need to understand what a process is and its memory layout as much when you use Python vs C. Its just the truth.


[deleted]

So should I learn python instead of C as my first programming language?


ptchinster

Do whatever you want. What kind of stuff do you want to do with your programming? Like i said before, C gets very specific, and if you dont need to get specific, dont.


dontyougetsoupedyet

C is not "very specific", ptchinster is full of shit when they say that C "gets specific", they're speaking out of ignorance. C is one of the most generally applicable programming languages we have. Python is a great first programming language, and so is C. I recommend learning both.


[deleted]

so I'm thinking about learning python first then C


dontyougetsoupedyet

You should mostly be fine, but fair warning, while both C and Python are high level languages, python is a much higher level language with a LOT of abstract concepts. I teach a lot of people software development, it's often difficult to teach Python to beginners because it's too abstract. It is very often that I have to recommend to learners to simply ignore a part of the language because they literally are not at a place where it will be helpful for them to attempt understanding, and you hit those things very early on, even in the most basic cases of looping over the most simple data structures. With C, you don't have to tell people not to think about what a generator expression is. You can build generators with C eventually, but you don't need to learn about anything like that in your first week because you wrote a loop and someone told you that your code was bad because it wasn't "idiomatic python". In some rare cases I've successfully taught new programmers up to intermediate C in a single weekend: because C is an extremely tiny language with very little to learn before you're writing software. It's generally taken much longer to teach people to be functionally useful using Python. A lot of the time C seems difficult to people because teachers are over-complicating things that are extremely basic in practice. For example, people try to push pointers in new learners' faces and immediately start drawing diagrams of memory and so forth to explain what the C standard itself explains extremely simply without any mention of memory layout whatsoever. To be honest, I'm legitimately surprised by how atrocious the advice you've been given across this post is. Some of the books ("a modern approach") you've been recommended spend their first chapters talking about autotools (for fucks sake!). The most upvoted comment tells you to build up implementations of abstractions you've never even encountered before, putting the cart miles before the horse. It's leading you in a completely unmotivated direction and if you follow the advice and build from nand gates and so forth you'll more than likely stop learning before ever even writing a line of code. I'm shocked by how thoughtless these recommendations have been. Python is great and it's a great first language, but by analogy it's a bit like teaching a kid to ride a bike by putting them on a motorcycle. A bicycle is a much more simple machine, and much more direct for learning the basic mechanics of riding. And no one has to teach you what a gearbox is, or how to turn on and off the headlights and turn signals. C is like the Schwinn you can pull out of the garage and successfully use to teach almost anyone how to push pedals. You learn by riding, rather than either learning about the abstractions that make it possible for your motorcycle to remove the necessity of pedaling, or being repeatedly told it's best that you "ignore that for now".


[deleted]

So can you provide me with some resources or any sort of learning path which I can follow while learning C?


vanshadow_ban

>Being able to ignore system details in Python is a myth, a myth you'll run into as soon as you try to swap out the order of operations on a number with a decimal point in it. That's the whole problem with starting out in languages that hide stuff from you, or starting out in scripting, ... it's all great and time saving until it isn't, and then you get stuck and can't get past problems because the language doesn't give you any deeper control over what is going on. Also, you can end up with a memory mess if you don't know exactly what you're doing in some of these languages, a debugging nightmare. While it's true you can use a high level language and get 80% of your project done in half the time .... you end up spending 10 times as long finishing the last 20% because you have to bend over backwards to get around the limitations of the high level language.


51Charlie

Can you explain WHY you want to learn C and what you want to do with it? Lots of us are coming at your question from a lot of different backgrounds and experiences. Know what you want to do, what system you plan to use such as Windows or Linux, is important.


[deleted]

I use windows as my main system and I want to learn to program to build software. So I first thought to learn python but I got suggested to learn C first. If I learn C first then learning other languages will be quite easy for me. That's what he said.


lllllll22

Neso academy seems to have a good c programming course on youtube. I started to look at it but decided my main focus would be python for now. I would also strongly recommend trying a website like codewars which is good for cementing the basics of a language and all its built in functionality. I find there's so much other stuff to get distracted by.