DEV Community

Aaron Canty
Aaron Canty

Posted on

Why am I finding C so difficult?

Hi folks,

Heading into the final few weeks of my last semester of year 2 at university and it's okay.

The one thing that is breaking my brain more than other modules, is the C module. Not sure why I'm finding it so difficult but it's mind boggling! I get the idea of pointers, structs, memory allocation, etc. but I just can't bring it all together to develop a clear or even a basic understanding of the language.

I think it's because I was spoiled - the last 2 years we've been doing Java, JS and Python mostly so it's been very high level and I didn't need to worry about things like the above. We're doing linked lists now and while I get the concept of a linked list, implementing them in C is a different ballgame entirely.

Has anyone else had a similar experience? If so, any tips to make C more palatable?

Thanks gang!

Top comments (10)

Collapse
 
veratiago profile image
Vera Tiago

Yeah, I feel you! Moving from Python to C is like driving an automatic vs. a manual. If you learn how to drive on an automatic car you will struggle with a manual one. Just stay strong and try to survive. C Is good to develop your brain, but you won't have to work with it when you get a job.

Collapse
 
ben profile image
Ben Halpern

I personally find a lot of stuff can transition from remarkably difficult to palatable with a bit of an aha moment. But I also want to say, IMO, C is difficult. Too difficult for me lol!

You seem quite capable if you're picking up all these other languages, so I'm sure you'll be able to pick up C, but managing pointers and memory and all that is just more work and is fundamentally difficult. There's a reason people build layers over it.

Whether or not you master C, just do your best. Once you're out of your studies, you'll only have to pick it up again if you really want to go down that path. If you wind up working in Python or JS, I guarantee you'll appreciate having had to struggle through C.

Collapse
 
spo0q profile image
spO0q

People use C-like or C-family languages for more convenience and specific tasks, for example, web-related projects.

C is the root, the kernel level. It's pretty hard to master, but I think it's worth learning as a second language to have a much deeper understanding of what happens with your code, instructions and variables.

In other words, it might make you a better programmer.

It's particularly useful for reverse engineering but not only. However, pragmatically speaking, I guess it's a bit of a niche market as there are now Golang, C#, etc.

Collapse
 
efpage profile image
Eckehard

C was created 50 years ago, so you shouldn't be surprised that things are not that convenient.

And mastering the language is not the only problem you will have to deal with. You will find that C (or C++) itself is missing many tools that are integrated in other languages. If you want to do more than print some numbers to the console, you will need to use some external libraries or APIΒ΄s. This can be very confusing, if you just started to learn the language itself, as some APIΒ΄s may introduce thousands of entry points and some very special new concepts.

Finally you have to be clear that C code runs very close to the bare metal. It is virtually impossible to write any C code, that is not bound to an operation system. So, your programs will be developed for windows and run on windows only. But not on linux, Android or MacOs. That is a serious limitation with growing impact today. For me, that was a reason to look for more portable solutions like Javascript.

Does C have any "educative" qualities? Like learning latin in school? I donΒ΄t thik so. Every language has itΒ΄s proΒ΄s and conΒ΄s, but there are many languages out there, that do not carry the load of an excessive long history.

Collapse
 
pauljlucas profile image
Paul J. Lucas

We're doing linked lists now and while I get the concept of a linked list, implementing them in C is a different ballgame entirely.

Can you implement a linked list in Java or Python from scratch without using either LinkedList (in Java) or built-in lists (in Python)?

Collapse
 
ecyrbe profile image
ecyrbe

It's not much that C is difficult. It's that it's too easy to get things wrong with C.
Indeed, you have have to control everything, every time. Resource Allocation, Deallocation are all handled manually (memory, files, mutexes, etc).
The language is missing a lot of concepts, like modules, generics, async functions, iterators etc.
Plus there are no standard library for things like data collections, networking, async programming...

Collapse
 
rdentato profile image
Remo Dentato • Edited

I might be biased but in all these years, I found that the biggest difficulty for those learning C was to not have the right "mental model".
The abstract model for C is extremely simple, you have:

  • A sequence of bytes called memory (each byte accessible through an address)
  • Three "streams" (stdin/stdout/stderr) that you can use to get/put sequences of bytes from/to peripherals.

Then you build from there. A variable? Just a sequence of bytes in memory. A pointer? Just a variable that can hold an address. The stack? A portion of memory. Local variables? Variable that are on the stack, And so on so forth.
What makes C difficult, I believe, is that this model is so simple that you have to build a lot of stuff yourself using those extremely low level concepts and there are quite a lot things that one can do wrong.
Libraries exist to ease the pain but you should have your foundations solid to put all the pieces together.

Collapse
 
dumboprogrammer profile image
Tawhid

I initially found C difficult because I was working witth high level languages but later on low level languages (yes even assembly) became readable to me due to slowly understanding and adapting the concept.

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

C was probably the second language I built stuff in. I didn't build that much, but it was the speed of C that made it attractive. Not really sure why I didn't use it more.

I mainly built utilities - I remember building a library to decode image files from Deluxe Paint, and place the result directly into EGA/VGA video memory... I think was about 14. I then used this library to load images in projects that I was building in a flavour of BASIC

Collapse
 
rrampage profile image
Raunak Ramakrishnan

Programming in C becomes much easier once you understand pointers well. My first programming language course in University was in C. I found these notes very useful to understand pointers.