60 Day Milestone!

“Time flies like a thief in the night.” Nice song by Burna Boy & Sauti Sol. This is for emphasis on how time can pass you by when you are not — aware.

We are gonna get there.

But, I am aware. I try to be — just occupied to notice. Be aware guys. It goes a long way.
They sent an email to congratulate or maybe motivate us on how far we have come. The programme commenced on valentines day. Lol. This will be a long post.

1. Libraries.

The Great Library of Alexandria in Egypt is/rather was known to be one of the worlds’ largest ancient library.

Why am I telling you this?

Nothing. I just want you to know history.

Anyways, it had everything. Almost. Some of the most brilliant minds of the period worked, studied and taught at the library. Then it burned down. For 6 months. Ceasar did that. According to History, and history is hearsay. So read more and know stuff. But he did it.
In modern times, that’s like Google is no more or Stack Overflow simply ceases to exist, or someone deleting your repos on Github. yikes.

Now in C , we have two types of libraries : Static Library & Dynamic Library.
We will look at Static Library for now.

  • They have a suffix (.a)
  • They hold code routines , functions, variables , anything really for us.
  • These are a collection of (.o) files and when we link them with our (.c) files , they become executable (they work).
  • This helps us to have code re-usability. No one has time to write the same function idk how many times. It’s boring.

Creating a static library.

  • We use a tool called an archiver(ar). You can create, list, modify and so on with this. Let’s say we want to create a library(mylibrary) and add all our (.o) files:
  • We first compile our (.c) files to (.o) files. We use :
gcc -c *.c  // * is a wildcard meaning all .c files
  • We now create a library and append all our (.o) files :
    ar — is the command name.
    -r — is telling the program to write into the library the (.o)files we compiled.
    -c — is command for creatingthe library if it does not already exist.
ar -rc mylibrary.a *.o
  • Then we index it . I can’t tell you precisely why we do this , but it’s important. And to do that :
ranlib mylibrary.a
  • To list and check if our commands have done the ‘ting:
nm mylibrary.a

2. argc , argv (My facts on this)

int main( int argc, char *argv[] )
  • argc refers to argument count , while argv refers to argument value is an array of strings, hence the *.
  • argc is always greater than 0. argv[0] is usually sort of reserved for the name of the program. Let me just give an example:
gcc -o myprog myprog.c
  • Our argc is : 4 while our argv is :
argv[0] - gcc 
argv[1] - -o
argv[2] - myprog
argv[3]- myprog.c
  • More information that cannot mislead you is here.

3. malloc

  • Twitter usernames. We change them according to our moods, tv shows , anything. What if Twitter said only 10 characters ? uh-no.
  • To combat that, malloc comes in. It says we can reserve a memory and points us to where it is — returns a pointer.
  • m(emory) alloc(ation) is just assigning memory to be used just in case.
  • There is the ‘traditional’ way of assigning memory i.e {int a[5]}. This is telling us we have an array a , with only 5 spaces given to us. Not applicable for us.
char *str = malloc(sizeof(char)*3);//This tells us that our guy str is storing the address of memory that is allocated , the size of 1 character , three times.
  • Example 2:
int *arr = malloc(sizeof(int)*5);//This now tells us that our arr pointer is storing the address of the size of one integer , 5 times. {sizeof} compels us to take to account , the size of each data type.
  • Malloc helps us not over allocate memory to waste it and also underallocate it.
  • When done, we need to free() the memory. Information here.


This is my fun personal project after watching the Transformers franchise. Not one movie used the I can Transform Ya song. Even in Bumblebee.
So I made a bot that will ask them daily if they will use that song. why ? Cause it’s a good [redacted] song. And that would be hella cool.

Here it is : https://twitter.com/TransformassB

4. C Preprocessors

  • The C preprocessor modifies a source code file before handing it over to the compiler.
  • It does this by :
    removing all comments
    include header files in the code.
    replace macro names with code.
  • These are essentially three uses of the preprocessor — directives, constants, and macros.
  • Directives are commands that tell the preprocessor to skip part of a file, include another file, or define a constant or macro & begin with a sharp sign (#).

Header files.
We usually do #include header.h to add header files.


  • If we write:

#define [identifier name] [value]whenever [identifier name] shows up in the file, it will be replaced by [value].

Example :

#define PI 3.1427 //
  • When we write PI anywhere in our code, our preprocessor will automatically sub it with it’s value {3.1427}

This will be a 20min post if I start on explanations but : more resources on this .

5. Macros and Structures .

  • Macros are what we have defined up there , the PI thing.
  • Structures ,rather struct are user defined data types. It’s like you as an individual. Let’s break it down:
struct individual
char *yourname;
int age;
char *yourlikes;
int yourphoneno;
char *yourfavemovies;
  • This enables us to have alot of values under a single name.
  • To access struct individual , we can name it and now access it.
struct individual you;you.yourname = "your_name" // we have changed it to your name

Pointers to Structures

  • There is a way with pointers, to deference it . We can use arrows and something.
  • To access elements of a pointer to a structure, you have to dereference the pointer and then access to the data using the ‘.’ symbol like above.
struct individual *me;
  • There is a simple way to do that, just by using the ‘->’ symbol. This is to get all the data in struct *me.
(*me).name = "Michelle"
me --> age = "22"
  • Those are the two ways we can access and change struct pointers.

There are so many I have left out but I have provided links for clarification and more information. Comment any corrections.

Commit Count : 532



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michelle Juma

Michelle Juma

My other github — but with more words.