How to Systematically Learn C Language?

Hello everyone, I am Xiao Bei.

Those who are familiar with me know that I have previously published many articles on learning paths, including operating systems and C++. Many students have urged me several times to talk about how to learn C language.

Here it is, the king of pigeons has arrived.

To reiterate, let me emphasize the importance of C language:

How to Systematically Learn C Language?
  • C language should be the first programming lesson for most students.

  • For students who are not majoring in CS, learning C language mainly involves mastering some basic programming methods; C language is just a medium.

  • However, for students majoring in CS, C language is the cornerstone for subsequent courses such as computer organization, architecture, operating systems, and compiler principles. A deep understanding of C language itself and the basic principles of programming languages should be mastered.

1. A Picture is Worth a Thousand Words

If you don’t want to read redundant text, just look at the mind map I drew:

How to Systematically Learn C Language?

2. Is C Language Easy to Learn but Hard to Master?

Many students report that C language is difficult.

In fact, compared to more modern languages like C++ and Java, C language has very few syntactic features; it is not like C++ which has become a hodgepodge.

C language only includes the most basic syntax of programming languages, such as variables, if, else, for, while, enums, structs, etc., plus a pointer.

But why do people find it difficult?

Let me share the reasons I found it difficult in my freshman year, mainly two points:

1. Too Few Libraries, Too Primitive

To write a slightly more complex project in C language, you need to first implement data structures and common algorithms, not to mention strings and serialization.

For example, in Redis, there are SDS, LIST, ZSET, HASH, etc.

This is extremely unfriendly to beginners.

If you want to create something interesting, you have to start by writing a linked list?

In Java, you can simply create a LinkedList or HashMap, which is incredibly efficient.

Later, when I learned Python, I realized this is the advanced form of programming; to write a web scraper, you just import a library and finish it in a few lines.

In C language, you need to write raw sockets to send network packets, parse HTTP protocols, serialize JSON, handle HTTPS, etc. (Of course, you can import libraries, but due to the weak package management in C/C++, it can be quite troublesome).

This is why beginners are often discouraged from learning C; they can’t create fun things and are left with a bunch of black boxes.

2. Memory and Pointers

Another common headache for C language beginners is pointers.

Pointers themselves are not difficult; they are just the addresses of variables.

But the problem is, what is an address?

Understanding addresses requires understanding memory, but since most students learn C language in their freshman year, they often lack foundational computer knowledge, making it somewhat challenging to grasp.

Memory is actually quite simple; you can think of it as a black box that provides read and write capabilities.

It’s like a delivery locker that allows you to store and retrieve items:

How to Systematically Learn C Language?

Where to read? Where to write?

Of course, you need an address; the address is like the number on the delivery locker, and the items in the locker correspond to the actual content stored in memory.

If you remember this image of the delivery locker, you will understand pointers.

What is a double pointer?

It is when the locker contains the number of another locker; in C language, for example:

int a = 10;
int *pa = &a;
int **ppa = &pa;

The memory pointed to by ppa contains the address of pa, and pa contains the address of a (no need to draw a diagram, just visualize it).

You might ask, what is the difference between a pointer, a double pointer, and pointers of higher levels?

It’s simple; if you don’t use two **, how do you tell the compiler that this place actually holds the address of another memory?

That way, the compiler can perform syntax checks; otherwise, how would anyone know if you are storing a variable’s address or another pointer’s address?

More detailed content has been discussed in my article about pointers:

Why are pointers regarded as the soul of C language?

However, from my perspective now, I find pointers quite simple and seemingly easy to understand; perhaps it’s due to the curse of knowledge.

The curse of knowledge refers to the phenomenon where once we know something, we find it hard to imagine what it was like not to know it.

Later, when I encountered Java, it was like discovering a new world.

In C language, when you allocate memory, you must remember to free it at the appropriate time.

Free it inappropriately? Sorry, a core dump is waiting for you.

Forget to free it? Sorry, a memory leak is waiting for you~

Writing pointers incorrectly? Sorry, memory overflow is waiting for you~

Stack memory overflow? In VS, it will burn you~

These issues are common for every C programmer.

In higher-level languages like Java, you just need to new an object.

Alright, enough rambling. Here is a systematic learning path for C language:

Phase 1: Beginners Should Read Less and Watch More Videos

This is truly a lesson learned through blood and tears. In my freshman year, I foolishly read the textbook and then did the programming exercises at the end of the book.

It was incredibly difficult; as everyone knows, textbooks often have a characteristic of being “not human language” to maintain their rigor and comprehensiveness.

For C language, beginners face a challenge of encountering various compilation and linking errors without knowing how to resolve them:

How to Systematically Learn C Language?

For example, this very basic error often makes beginners panic.

When encountering such situations, my advice is to carefully read the error messages; the solutions are often found in those notes. If you really can’t solve it, just copy the note and search for it on Google.

At this stage, you need three resources:

  • One is to supplement your CS foundational concepts, which is an introduction to computer science.
  • Two is a good book on C language.
  • Three is a quality C language video.

For each point, I will only recommend one that I think is the most suitable to avoid you falling into decision paralysis:

  • Introduction to Computer Science

CS50, a Harvard introductory computer science course, I can’t remember if I watched it in my freshman or sophomore year, but I felt like I had struck gold. Here is the link:

https://cs50.harvard.edu/college/2021/spring

One point that still stands out in my memory is when the teacher explained binary search by directly demonstrating the process of looking up a dictionary and even tearing a dictionary apart on stage…

How to Systematically Learn C Language?

Additionally, this course uses C language as the teaching language, which is quite rare.

Because many top CS schools abroad now use languages like Python or Scheme for their introductory courses.

However, you will find that in CS50, not much C language syntax is taught; C language is merely a medium to convey programming concepts and guide you into computer science.

It is not teaching C language.

  • C Language Video

No need to say much, I recommend a course by Professor Weng Kai from Zhejiang University, which I used to watch on the subway. You can search for it on China University MOOC. Here is the link:

https://www.icourse163.org/course/ZJU-199001

Speaking of which, I must say a few more words about Professor Weng Kai. I have watched several of his courses, and my most direct impression is:

His explanations are thorough, his voice is pleasant, and he pays great attention to detail. Here is a screenshot of the anonymous evaluation of Professor Weng Kai from Zhejiang University:

How to Systematically Learn C Language?

In a nutshell, Professor Weng Kai genuinely wants to teach the internal principles of computers and programming languages in an accessible way.

  • C Language Book

The “C Programming Language,” a book known as the Bible of C language.

In a short length, it covers most examples in <stdio.h> and <string.h>, and the exercises are classic, starting from hello world to binary search, binary trees, quicksort, hash tables, and even using recursive descent to write lexical analysis, helping you understand complex declarations.

However, understanding every example in it does require some foundational knowledge, but it can still serve as an introductory book that you can read multiple times.

By the way, I’ve been saying that learning programming requires a lot of writing, but many beginners don’t know what to write.

Here, I will provide some examples you can practice after learning the basic syntax of C language:

  • Linked List

Just use C language to write linked lists repeatedly, from the most basic linked list insertion, deletion, singly linked, doubly linked, circular linked lists.

To reversing, merging, and splitting linked lists, etc.

Don’t underestimate the basics; many students may not get it right even in their senior year, which tests whether they are detail-oriented and whether their logic is sound.

Will they accidentally break the chain while operating?

  • Write Some Small Projects

For example, a library management system, Tetris, Snake, etc.

The amount of code is mostly between 500 – 1000, which will comprehensively utilize functions, file operations, dynamic memory, pointers, and other key elements.

Phase 2: Understand Memory, Read Books, Write Code

How to Systematically Learn C Language?

This phase requires mastering some knowledge of computer systems to learn well, such as virtual addresses related to operating systems, and function call stacks related to assembly.

For example, many students who have studied for a long time still do not clearly understand the difference between variable declaration and definition, and what extern does; these actually require understanding memory partitioning.

The core of C language lies in pointers and memory; whether you can learn and use C language well depends more on whether you have solid knowledge of computer architecture, storage, and operational principles.

Therefore, I strongly recommend that while learning C language, you also understand concepts like two’s complement, binary representation of numbers, memory, and assembly, especially memory and assembly, as these two greatly aid in deeply understanding and skillfully using pointers.

I won’t go into detail; the books to be introduced are all in this mind map.

  • In-depth Study of Pointers

“C and Pointers” and “Understanding C Pointers” are excellent books that cover all aspects of pointers, highly recommended.

  • Compilation and Linking

Understanding these two processes won’t necessarily improve your coding skills, but it will help you clarify some compilation and linking errors, so you won’t be confused.

For example, common errors during linking include undefined reference and redefinition of symbols.

Once you are familiar with the linking process and symbol lookup process, resolving corresponding errors will become much easier.

  • Assembly

Assembly is beneath C language; if you know assembly, you can strip C language down and see the underlying implementation. For example, everyone discusses the difference between arrays and pointers; you can write a program and then use gcc -S to see the assembly code, and you will find there is not much difference…

You don’t need to be able to write assembly; just being able to understand some parts is sufficient; there’s no need to memorize various instructions and addressing modes.

Alright, today’s journey of learning C language ends here. In fact, there are many things not mentioned, such as the Linux C direction.

The main goal is to highlight learning C language itself without overshadowing it, so that everyone doesn’t lose their direction.

Additionally, I have compiled the recommended books:

How to Systematically Learn C Language?

Once you complete this set, you should have no major issues with C language.

If you need it, you can click the public account below, follow it, and reply with “C language”.

Wishing everyone a happy weekend~~

Leave a Comment