C is a stripped-down language. It gives you the bare metal. It does not even include functions to read from a keyboard or write to a screen. If you want that, you have to build it.
Everything beyond the absolute basics lives in libraries.
You know the stdio library. It handles standard input and output. There are others for math. String handling. Time manipulation. They exist so you don’t have to reinvent the wheel every time you start a new project.
But why stop at what the standard provides?
Putting code into libraries makes it reusable. It lets you split massive programs into manageable modules. Easier to test. Easier to debug. You can pull code from your old projects and drop it into new ones without copy-pasting blocks of logic.
Let’s look at how to do this.
Extracting Logic Into Functions
Take a standard C program that fills an array with random numbers and sorts them. Here is the raw code:
This code does three things. It fills an array with random numbers. It sorts them using a bubble sort. It prints the result.
To make a reusable library, we need to isolate the sorting logic.
Step One: Generalize The Sort
Extract the bubble sort code. Turn it into a function.
Since the array a and the constant MAX are global, the function doesn’t need parameters initially. It also doesn’t need to return a value. Just use local variables for x, y, and t.
Now update main to call this function instead of running the inline loop.
It works. But it’s still tied to a global array.
Step Two: Pass The Array
We can make the sort function truly generic. Pass the array itself as a parameter.
The signature changes to:
This tells the compiler to accept an integer array of any size. The body of the function stays exactly the same. You just update the call in main :
Notice something odd? We pass a, not &a.
Even though the sort function modifies the array, we don’t need the address-of operator here. It seems counterintuitive if you are used to pass-by-value languages. You might wonder why this works without pointers explicitly in the call.
It is because in C, arrays decay to pointers when passed to functions. The function receives a reference to the start of the array in memory. That is why it can modify the original data.
Understanding this distinction is the gateway to mastering pointers. Without it, C libraries are just static blocks of code. With it, you are building modular, portable systems.





















