End of Probation

Data Structures

Yay! It's finally the end of the probation phase and I'm glad to say that I passed with scores I'm proud of. It's been GOD all the way. I know it's just a month I concluded and really should be wary of what comes next; believe me I am. But I celebrate GOD for even the seemingly little things. I'm especially glad because it's not been easy combining content writing with the programme. I've especially been taunted by even peers who sarcastically tell me I have a lot of time on my hands and that I might not have anything better to do. GOD forbid, if the otherwise happened, I might not be able to tolerate insensitive criticism. Do not misunderstand me; I believe in criticism, but only when it's constructive. So, I can't help being happy.

Without further ado, this week majorly involved working with arrays, strings and pointers. Basically these three are are data structures. Well in most programming languages, strings are actually data types; same as integers and floats but it's different with C. Data structures are basically a way to structure data. I would call them ways to arrange data to make data easier to work with; finding, using, reading, including insertion of deletion of data. The type of data to work with, coupled with the programmer's goal will determine the best data structure to use. The discretion to use the most efficient data structure for the relevant data, taking into consideration the objectives of the program and sometimes other factors is what I call algorithm. Assuming a scenario of transportation, the different forms of transportation; rail, road, air would be the data structures. Knowing to take a cab to travel kilometers, flights for longer miles, while considering other factors like your financial capacity would be algorithm.

Arrays are data structures that allow you to store variables of the same data types, side by side. Variables are containers that hold data values; you might think that variables also hold data so why would you need an array? Well, a variable can only hold one datum at a time, so if you want to work with 50 or more data, you would need to declare 50 different variables. Besides the unnecessary repetition you would have to go through to achieve that, you are also more likely to make more errors; you have to think of a different variable name every single time, making the mistake of using a name more than once while very likely, would cost you dearly; making the mistake of reassigning variables, while thinking you declared new ones. Why go through all this when you can just use an array; you can do the declaration just once and you only need one name. It's also pretty easy to work with values in an array as you can simply access each value using its relevant index. Arrays however have a fixed size and you need to be sure of the array size you need during declaration.

Strings, while being data types in other programming languages are basically arrays of characters in C. C has no string data type so use an array of characters to work arround that. We just need to remember to end the characters with a nul terminator(\0). The nul terminator marks the end of the string an tells our computer we're actually dealing with a string this time, not an array of random characters.

Pointers, on the other hand are like "special" variables. Normally, variables are containers that hold values. As containers, they occupy a space in the computer's memory and each memory location in the computer an address has an address, yes the way houses, schools, hospitals and almost every location has an address. A pointer is a "special" variable because unlike a variable that stores data values, the pointer stores the address of these variables; this way you know exactly where variables are located and can directly affect and work with their values. To declare a pointer, you include the type; which is basically the type of variable you want to "point" to. For example, an int pointer cannot "point" to a char variable or vice versa. You then add the () operand and the pointer name. Basically the same way of declaring a variable but with the () to tell our computer that this is a pointer and not just a variable. You can interpret the () as "this is special". Initializing a pointer isn't too different from that of a variable either, except the value of the pointer is the address of the variable, which can be indicated using the ampersand/address of (&) operator. So if we declare an integer type variable n as: (int i = 5;) we can easily do the same for a pointer x as (int x = &i). The major difference between these two is the (*) that screams "this is special" and the value 5 being replaced with the address of the variable i (&i) because while variables normally store values; pointers store the addresses of these variables.

This probation period was really daunting and while I hope it gets easier from here on; taking a sneak peek at the planning section perished that idea. I intend to continue thriving though and I hope we all do.