DEV Community

Cover image for Data Types (Programing Fundamentals Part — 2)
Pixel and Code
Pixel and Code

Posted on

Data Types (Programing Fundamentals Part — 2)

This tutorial is part of a series I created to teach beginners the basic fundamentals of programming before diving into any specific programming language. If you're a beginner, you might want to start with the first part, but it's entirely up to you. Professionals are also welcome to read it and share any feedback on mistakes or unanswered questions, and it would be greatly appreciated if they could help address any incorrect or missing answers in the comments.

https://dev.to/pixelandcode/do-not-start-to-learn-programming-before-this-programming-fundamentals-part-1-4a0n

In previous blog we talked about variables. Now let’s talk about data types and I will teach while assuming that you are 5 years old.

Data Types

Before understanding them, its better know about some basic datatypes. May be some people will get it as soon as reading the types.

int (it is used to store whole numbers like 5,0,-3,22)

//int example
int car = 5;
Enter fullscreen mode Exit fullscreen mode

float (Used to store numbers with decimal points, but with limited
precision like 3.14, -0.5)

//float example
float car_price = 299.9999999;
Enter fullscreen mode Exit fullscreen mode

double (Similar to float, but stores numbers with more precision (more digits after the decimal). Good for scientific or financial calculations.)

//double example
double pi = 3.141592653589793 
Enter fullscreen mode Exit fullscreen mode

char (Stores a single character, like 'A', 'z', or '9')

char a = '9';
Enter fullscreen mode Exit fullscreen mode

There are more of them but let's get the basic understanding first from them.

Understanding about writing characters
If you have been careful, you might have noticed that in the first example we wrote:

int car = 5;   // a number
Enter fullscreen mode Exit fullscreen mode

But later we wrote:

char a = '9';  // a character
Enter fullscreen mode Exit fullscreen mode

Notice the difference?

  1. When we write a value without quotes (like 5), the computer understands it as a number that can be used in calculations.
  2. When we write something inside quotes, the computer treats it as text/character data instead of a number.

Important detail:
Single quotes ' ' are used for a single character (like '9', 'A').
Double quotes " " are used for strings (text with one or more characters, like "Hello" or "9").
So:

  1. 5 → number (int), can be used in math.
  2. '9' → character, not directly usable in math.
  3. "9" → string (text), also not directly usable in math. These were some basic datatypes. There are more datatypes like string, Boolean etx but it can get confusing for you to remember too many datatypes as a beginner, and you can learn them later.

If you still didn’t understand datatypes, it might be because you missed the first part where I explained it with the example of an almirah and shelves. Imagine you have a box labeled “CAR” that contains your toy car. The box is like a variable holding the value “car.” Now, to keep your boxes safe, your mom gives you an almirah with three shelves — one for books, one for stationery, and one for toys. These shelves represent different datatypes. If you place your toy on the shelf meant for books, it will be confusing and hard to find, so you must place it on the toy shelf instead. Similarly, in programming, every value needs to be stored in the right datatype so that computer can understand.

Top comments (0)