what is the best way to learn C ? I know basic python but would like to learn C, I tried searching online but couldn’t find a good resource that’s good for a beginner like me. any suggestions ?
There is no single best way for every beginner. When I web search for “how to learn c programming”, then a lot of tutorials will appear. It would be good to know what does make them “bad resource” in your opinion, so one can give a better suggestion. Also it would be good to know what your end goal with C is; systems programming? cli programming? why is Python not enough? do you want work as a C programmer somewhere?
Read a book about C, follow the examples and try to solve stuff alongside, play with the code. Take your time. And look out that its not too old, as the language and tools changed over time. Here is a suggestion: A complete and up to date open source book as downloadable PDF
I just want to learn the low level stuff about how programs are written in C, and things like how system starts processes, how programs interact with the OS etc, (I guess that’s basically systems programming ?).
It would be good to know what does make them “bad resource” in your opinion
some that I’ve looked up seem rather shallow and don’t explain things well, what I’m struggling with is the memory allocation stuff, like what is malloc ? realloc ? calloc ?
why is Python not enough?
Python is enough, I’m happy with it; I just want to learn more.
https://jsommers.github.io/cbook/cbook.pdf
Might be a good way for someone who is familiar with a higher level language.
Than there is of course “The C Programming Language” by Ritchie and Kernighan and “advanced programming in the unix enviroment” by stevens and rago.
So, i’d guess just get your feet wet with small stuff. Find out how to take arguments from the command line, or read a file, maybe programm a simple guess the number game. After you are more familiar with the syntax and so on you could look into using your c code in a higher level language. For python you’d have to look into ctypes for that.
One of the thing I recommends is to start small. Going from Python to C is quite a leap, because C language requires some fundamental computer science understanding when you write codes that offers no railing or safety net when you make mistakes. I would actually suggests that you start with C#, it is very forgiving when you make a mistake and have various tools to help you identify the bug in your program.
Big part of C# is that there is available video tutorial on an introduction to C# provided by Microsoft and it have subtitles. The biggest reason why I would recommend C# to beginner is simply that they offers a lot of resources to help beginners understand the fundamental of programming in general. They have tons of books, video tutorials, vibrant community, and so forth. Also C# can run on wide range of platforms, Windows, Linux, Mac OSX, Raspberry Pi, and so forth. Once you master C#, you’ll find that a lot of the knowledge you gained from it is transferable to C, C++, Rust, DLang, and so forth.
C#
eh… those are fundamentally different, C is not object-oriented so OOD part goes straight out of the window. The only thing similar about them is syntax to some degree (which is really irrelevant), approach is completely different.
Yeah, but when someone is completely new to programming, it’s best to start somewhere easy where there are quite a lot of tools to help them fix bugs in code. In C# IDE, it have a lot of visual indicators to help them identify bugs, debugger is pretty comprehensive and integrated, and there are quite a lot of resources to introduce them to programming in forms of videos and documentations and community. The goal of learning C# is not to only program C#, but to get them acquaintances with general programming such as for loop, memory management like using disposal in C#, recursion functions and so go on. They can use C# as a starting point to just basic programming and then once they are comfortable, they can move on to other language that they are curious about.
Why do you want to learn C?
This here might be an A B problem, so I’d like to check what is your goal, before recommending how to get into C. For most use cases there are much better options around nowadays.
Many of the use cases you needed C for in past decades now have better alternatives.
This is a primo StackOverflow style answer.
Tbh, A-B-problems are something super common in IT. So much time is wasted by going down the wrong road because someone comes to you with the apparent solution that they thought of, instead of just posing the problem they want a solution to.
In case of this post, there are quite a few reason why the OP wants to learn C after learning a bit of Python, and some of them have C as the correct solution, some don’t.
For example:
- OP wants to make C-modules for Python -> C is the correct language, though Google might already have a fitting module
- OP heard that Python is slow and C is fast -> Improve your Python skills, learn algorithmics
- OP has a legitimate problem to solve where Python is not fast enough -> Check out Java/C#/Rust or, if it really has to be, C++
- OP wants to program microcontrollers -> C is good, but might want to check out MicroPython
- OP wants to program games -> Unity + C#
- OP wants to go real low level -> C
- OP is a masochist -> C or Assembly
Especially the “C is faster” argument is often a trap for new programmers, since C is only faster if you really know what you are doing. C can also be much slower if e.g. you mess up memory management. Or, more common, C is not at all, because the rookie programmer gets stuck at arcane error messages that they can’t fix.
In most cases the pure execution speed is not what is limiting the performance, but instead the algorithms and data structures used. For example, if you loop through a large array to find an entry it doesn’t matter that the looping is 4x the speed, when you could also just use a hashmap/hashset, which will be orders of magnitude faster.
deleted by creator
deleted by creator
At the risk of starting a flame war, I find the gnu style absolutely unreadable garbage. The BSD style is far superior, imo.
I know that’s all personal preference (and of course dependent of if one happens to contribute to particular projects), so you do you. But damn.
Going right from python to C is rough. But you can try. I would suggest watching YouTube tutorials or reading a Book about C
Harvard’s CS50 course is free online and does a pretty good job touching on the fundamentals of C in the first half.
Ever since edX had their IPO, I hesitate to call it free. Each edX course is free for a limited time now and their prices are way too high if you aren’t interested in a certificate and the certificates aren’t worth much of anything in the employment market. They need a $50 option for no certificate and “unlimited” course access. But with shareholders, would they ever consider such a thing?
The content isn’t exclusive to edX, though.
Harvard hosts it outside of edX.
That puts a bit of organizational overhead on the learner. The material is all there and organized, but it’s not as conveniently presented nor does it mark your progress automatically. I like that they switched to GitHub code spaces and away from cloud9 which complicated things further.
Personally I wouldn’t jump straight from python to C, python tends to hold your hand quite a bit and C will absolutely let you shoot yourself in the foot.
Personally I consider languages like c# and java a middle point but I don’t do C so I’m probably not the best person to gauge that, just have seen a lot of people try and fail to jump straight into C from high level languages
Maybe cross posting this to https://programming.dev/c/c_lang and https://programming.dev/c/learnprogramming might get some quality responses.
there’s a lot of different C’s out there - I mean coding for microcontrollers looks really different to coding graphics with opengl, for example, especially for a beginner.
What do you want to do achieve with C specifically?One thing that I did that was super helpful was to try to replicate something from Python.
(Yes, I know you can just look at the Python source, but just trying to ignore that and thinking about ways one might go about it. Not for production, just for practice)
For example, I wanted to try making something akin to Python’s lists in C, with all of it’s various operations, e.g. append, insert, length, split, reverse, copy, etc. I started with a single data type, and then wanted to expand it to accept whatever data type I threw at it. A project like this covered a lot of C concepts and really helped me get a grasp on things like data structures, memory management, search algorithms, etc.
Coming up with ideas for programs to code is the part I struggle with the most, so I like to use codewars.com when I’m trying out a new language. Really, the only way to learn is to practice, practice, practice.
the “best” way to learn a language is going to change from person to person, BUT i would take a look at Modern C by Jens Gustedt if you haven’t already: https://gustedt.gitlabpages.inria.fr/modern-c/
deleted by creator