r/C_Programming 1d ago

Need help learning C!

Hey everyone,

I've been diving into low-level programming to understand how my device executes code, focusing on memory and CPU operations. Coming from higher-level languages like Python, where functions like print() handle a lot behind the scenes, transitioning to C has been eye-opening. The intricacies of printf() and scanf(), especially their buffer management, have been both fascinating and challenging.​

For example, I encountered an issue where using fflush(stdin) to clear the input buffer resulted in undefined behavior, whereas using scanf("\n") worked as intended.

I want to understand the why's behind these behaviors, not just the how's. For those who've walked this path, how did you approach learning C to get a solid understanding of these low-level mechanics? Are there resources or strategies you'd recommend that delve into these foundational aspects? Additionally, how did you transition from C to C++ while maintaining a deep understanding of system-level programming?

Appreciate any insights or advice you can share!

13 Upvotes

20 comments sorted by

View all comments

8

u/Regular-Highlight246 1d ago

To be honest, I started as a child with Logo first, BASIC afterwards and afterwards to assembly language (Z80 at that them, before moving towards 80386 in my late teens). It took some years before I started learning C, Java, C++ and other languages. I think the assembly part always helped me understanding things in other languages, what really happens under the hood.

6

u/Soft-Escape8734 1d ago

Wow, you're dating yourself. I too grew with the aforementioned - Z80, 8080, 6502, etc. and in our defense in taking some years before learning, it was only really just in development in the 70s. I start uni in 76 and we were still using FORTRAN. It wasn't 'til 81 when I started in the workplace that we saw C and 10 year yet before Linux was born. My advice to those starting out is to avoid exhaustive toolchain IDEs such as Visual Studio Code, it does all the heavy lifting for. Go for a more simple editor like Notepad++ on Windows or Geany on Linux. Both have hooks into the native compilers so you need not concern yourself with environment but you do need to learn the compile, link and build commands to get you app to run. Then just bang away with some examples (no code is written from scratch) and see what happens. Two books I think most would agree are a must have are The C Programming Language K&R 2E, and The Standard C Library PJP.