Hello everybody,
Recently, I tried learning multiple programming languages at the same time (for those curious, I was working on C, C++, JavaScript, and Python). At first, I assumed they would all be completely different since they are used for different purposes. But I quickly realized something interesting: their basics are almost the same, with only a few differences and extra features here and there.
What I’m trying to say is this: the fundamentals of programming remain the same no matter which language you choose. And once you understand these fundamentals, learning any programming language becomes much easier and faster.
That’s exactly why C is often recommended as the first language to learn — it gives you a clear understanding of the fundamentals. In this series, I’ll explain these fundamentals to you as if you’re 5 years old.
But before we start, let me tell you this: You’ll be learning the fundamentals across multiple blogs, not in one giant post. This way, you won’t get bored reading a long wall of text.
This is Part 1 of the series.
So, let’s get started! 🚀
Variables
Ok, let’s assume you have a toy car. You want to keep your car in a safe place so that it doesn’t get lost. So, you find a box to store it. But there’s one problem — you have multiple boxes, and you might forget which one contains the toy car. What will you do? You’ll write CAR in big letters on that box. Now you’ll always know which box holds your car.
Congratulations! That’s it — you’ve already learned what a variable is.
Now, let’s see how this is defined in a programming language.
int car = 1;
int → This tells the computer that the box will store a whole number.
car → This is the name of the box (the variable). Just like labeling a box CAR, this name tells you what’s inside.
= 1; → This puts the value 1 into the box. It’s like putting one toy car inside the labeled box.
So, this single line creates a variable named car and stores a value in it.
You probably had a question in your mind now that why we write int in front of car? because computer reserves space differently for each data type. if you write int in front of the car. it will understand that user is trying to create a variable to store whole numbers, so it reserves 4 bytes in the ram for car variable but let's say that you want to store your name or may be a number something like 1.1, 2.009. What will do. Well, it will be explained later in the blog to keep you interest.
if you already understood why we write int, great you can skip to next para but if you didn’t it is completely ok and let me explain you in simple language. Now we know that you have a box named CAR with car toy inside it. Let's say you need a place to keep that box now. You do not want to keep it where it can get lost, right. Your mom already knew this that if any of toys got lost, you will cry. So, she made you a little almirah (cupboard) with different shelves. On the top shelfs you can keep your books, on the second shelf you can keep your stationary and on the third shelf you can keep your toys. Now if you keep your box at some other shelf than third shelf (toy shelf) you can get confused while finding your toy car later. That is why you keep the box in the third shelf name toys. That toy shelf is the type of your data. In programming we are saying to the computer that store car variable the integer shelf.
[Why variables are important? Answer is simple the data to access later. I am sure you have played a game which had score system. That score is stored in a variable. if there were no variables, maybe you would not have had scores system in games.]
If you have any questions, or if something wasn’t clear, feel free to ask in the comments — I’ll be happy to explain it better.
Part 2 is coming soon! The exact date depends on my motivation 😊. If I get good responses, I might publish it as soon as tomorrow. Otherwise, it could take a few days.
Top comments (0)