As learned earlier from the previous introduction to data types, the C language uses a defined type of value called datatype to communicate with the computer. Expanding our perspective on data types, the C data types can be categorized into two types: The primary data type and the secondary data type.

For Primary Datatypes, please refer to Datatypes in C.

 

Starting a new journey..

Learning a language is none of a big deal. I have said that before. I have mentioned that learning a language helps you in real life as well. So, why not try to understand this language using real-life problems!! Let us start the journey!!!

In your life, you guys have seen a lot of things. And you everyday categorize those things. Like, if you see a banana, you say its a fruit, or if you see a tiger at the zoo, you know its an animal. A similar categorization happens in a language. As the computer cannot categorize on its own, we need to help it out. And that is where datatypes come into handy.

 

What are Arrays?

Consider yourself going to shopping mart. If you would like to purchase some home utility, you might look for that section at the mart. What marts do, is a similar example to that of an array! The mart arranges everything according to the type of item. A similar situation is seen in an array, where quantities (values) that have the same datatype (category) are stored at the same location.

So, how does this help? It helps in the same manner as it helps you to categorize items in a mart. It reduces your time to find the object and lets similar objects be together and give an easier access to it.

What are Pointers?

Ever considered to think how the shopkeeper at the medical store remembers all the medicines you need! Well, he secretly uses pointers! (Yes he does!!). In order to find the medicine, the shopkeepers have to remember the location of the medicine at the store, similarly, it is sometimes required that we access the location of any variable (object)  that we have written in our code. For this, the pointers come to rescue. They store the address (location) of the variable (object) you want to!

What are Structures?

We are yet in the shopping mart, right? So, let’s explore the mart further. Let’s buy some clothes! Reaching to the clothes section, you see soo many varieties, there are shirts, pants, tops, jeans, and various other stuff for different genders and different age groups. Now, what is this? This section in itself has soo many categories! Well, this is an example of a structure. That is, it contains a collection of different objects ( shirts, pants, etc) that are of different categories ( gender, age, etc) under a single name (clothes).

Hence, structure can be understood as a collection of data of different data types that are under one name!

What are Unions?

So, in our shopping mart, we have all the different categories of items! Well, the Shopping mart is an example of Union.  Confused? Well, it is easy to understand, a union is nothing but a collection of data (objects) of different data types (clothes, vegetables, fruits, etc) under one memory space (the shopping mart).

What is Enumerated Data Types?

Now, consider yourself to be the owner of the shopping mart! What will you do! You might add a lot of categories into the mart, maybe a gaming section or even a makeup section! won’t that be a fun?

Well, this is a merry dream (unless one of you are an owner!), but worry not, you can do this using the enumerated data types where you can invent your own data types (categories like gaming section)  and define what values the variables (CoC, Counter-Strike, etc) of this data type can take.

Hope you guys could understand the usage of datatypes in C as well as in our real-life! These secondary data types will help you program your computer effectively and reduces the labor to code. In case, you have question, feel free to ask in the comments below. Good Day!
Share This