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 ?
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.
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 reasons 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.