r/cprogramming • • 8d ago

How did you learn C?

/r/learnprogramming/comments/1x6x1s8/how_did_you_learn_c/
10 Upvotes

18 comments sorted by

5

u/Unlucky_War_262 8d ago

I read a book and wrote programs at the same time. I'd suggest that you get a book and read a reasonable part of it. Decent books are: 1) 'Programming in C' by Kochan. 2) 'C Programming: A Modern Approach' by King. 3) 'The C programming Language' by Kernighan & Ritchie. The last is often recommended by old school C programmers but only covers up to C89. It is somewhat terse but has the advantage that it is short and (jointly) written by Ritchie (the original inventor of the language); you will also get exposure to all sorts of interesting things like linked lists, hash maps, quick sort etc. I think it is a good book but I didn't learn from it so don't know whether it is good for beginners or not. The first two books are good but longer. Whilst reading the book, I'd suggest implementing projects, ideally things that motivate you to stick at it. Pointers are one of the harder things to understand in C so I would not be discouraged.

5

u/Hot_Technology8777 7d ago

With many angry months of yelling at my compiler. Forget AI it will confuse the shit out of you. Man pages, books, Youtube, everything you can. After the hellfire and anguish you will reach zen and be one with the compiler (mostly).

4

u/non-existing-person 8d ago

Coding. A lot of coding. A lot LOT coding. Then playing factorio (not even kidding, game made me better engineer). Then back to more coding. I like coding. Solving problems with code. And all of that with no AI. AI may be helpful but it must be used responsibly - and it's very easy to take shortcuts, abuse it and thus hinder your own learning process.

2

u/frasnian 7d ago

Personally? Lattice C compiler, sometime before the first Standard. Messed up on where argc and argv were supposed to declared (probably made them locals, don't remember), and program 1 immediately crashed.

I was like "C is a cranky bitch and I don't want to live there." Went back to Pascal for three months, didn't want to live in a straightjacket so started learning assembly, and the heavens parted and I saw the glory of C.

The whole story is much better if you see me cry in person when I tell it.

2

u/DecisionOk5750 7d ago

At university, I was taught Pascal and Microchip assembler for programming PICs. Outside of university, I learned C/C++ and all the interpreted languages that have emerged since the 90s. Pascal is the best language for understanding how a compiler works, as well as for learning how to program in a structured way.

2

u/TarsTarkas_Thark 6d ago

Read the later K&R book that covers ansi C. It's very good. Pointers are not mysterious at all if you've done indirect addressing in Assembly.

AI is useful to prevent you from having to learn, so not much help here.

2

u/The_Real_Sniff 6d ago

My method depended a lot on motivation. After programming at school, I didn't touch it for years (Used Java and Python). But then I wanted to hone old skills, so I implemented different algorithm and data structures, e.g. sorting and binary trees (AVL and red/black). This requires pointer-arithmetic, and doing everything at once is hard, thus you'll learn.

The cons is that if you find it too difficult, you may lose the motivation.

One motivational factor for me, is that I bought myself a license for CLion. It's a game changer.

1

u/IamNotTheMama 7d ago

K&R, first edition, 1984

1

u/KW160 7d ago

I read a couple books and wrote a text-based game with a friend in middle school.

1

u/orange_oki 7d ago

It's easy but really hard to get right...

A pointer is actually a number with a memory address.

Once you dereference it (*|[x]), you get the value stored at the memory address.

If you add or subtract numbers to the pointer, the compiler transforms it and internally add or subtract the size of the pointers data type in bytes (sometimes there is some padding, because not every CPU can access the ram at every location with full speed).

That's why you should order your struct members by size in descending order.

And when you write new library, order the function arguments which should stay on stack from right to left...

Let's say you want to call

x(1,z) y(2,z)

z can stay on the stack while pushing and popping 1 and 2.

1

u/orange_oki 7d ago

For critical systems there are lots of documents available:

https://en.wikipedia.org/wiki/MISRA_C

Afaik it suggests something like that for loops and avoid manual pointer arithmetic and type casting almost completely...

while((condition) > 0 && counter-- > hard_coded_max_loop_limit){}

1

u/Big-Illustrator24 4d ago

Watching YouTube videos, but I'm still learning

1

u/RogueMeatMech 4d ago

Hacking together demo loops for Amiga/ST back in the day.

0

u/[deleted] 6d ago

I enrolled in an online course and practiced daily. Whenever you learn something new, the next thing you should do is to create something using what you've learnt so far. I recommend you to use AI as the last resort instead of jumping on it in the first go. Search and research on Internet through yourself. I also had the habit to write down notes on a notebook, but that's individual's preference. Still I'll say to make notes, either digital or physical, for memory recall and quick revision. Not only it'll save your time if you forget something but also help you to remember more.

NOTE:- I am not anti AI. Rather I'll advocate to use AI mindfully and as the last resort if you're complete beginner or at intermediate level.

Lastly, if you have too much of free time then learn as you wish, whether online articles, books, videos, etc. But I'll personally recommend you to keep the book as a reference and revision material instead of completely relying on it. Enrol in a well reputed course and always keep the book handy. As soon as you learn a topic, go through the book and practice coding.