I'm in my second year of computer science and my data structures and algorithms course uses C. I don't know much C yet. Do I need to master it first, or are the fundamentals enough? What should I focus on this semester?
How much C do I need to know for a DSA course?
Answers
You don't need to master C before starting DSA. Aim to get comfortable enough that reading and writing C doesn't distract you from the data structure.
Start with compiling and running a small program, then cover functions, arrays, strings, structs and pointers. Pay particular attention to passing pointers to functions, dynamic allocation with malloc and free, and recursion. Those will come up when you implement structures such as linked lists and trees.
Learn the language alongside the course rather than waiting until you feel finished with C.
Reply to this answer
I'd put pointers and structs near the top of the list. Make a small linked list, add a few nodes, traverse it and free the nodes. That gives you a concrete reason to use both, instead of trying to memorize pointer syntax in isolation.
Reply to this answer
Check the course materials and work through the early exercises as they're assigned. The class may introduce some of the C you need, so you don't have to treat every unfamiliar topic as something you should already know. If the exercises assume more C than you have, ask the instructor what to prioritize.
Reply to this answer
You can leave things like bit tricks, unions and function pointers for later unless your course uses them. Same goes for file I/O and build tools beyond whatever you need to compile the assignments.
C has a relatively small core, but using it correctly takes practice. In particular, don't just learn the syntax of malloc and free. Trace who owns each allocation and when it gets released.
Reply to this answer
A more thorough route is to work through an introductory C book in parallel with the course. The C Programming Language is one option, though some of its syntax and examples are dated, so use a modern reference alongside it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Jorvik.6m:
One useful detail: C passes arguments by value. Passing a pointer lets a function access or change the object the pointer refers to.