# 1.2 Data Types

&#x20;We use different types of data when programming. In this tutorial, we will learn about the data types used in C programming such as: int, float, double, char etc. When we declare a variable type, the data type determines how much storage that variable will take, what kind of data will be in that variable.

int type data Integers are integers which can store values ​​like zero, positive numbers, negative numbers (0, -5, 10) etc. but cannot store any decimal number.

```c
int rollNumber = 11;
```

The size of int is taken as 4 bytes of computer memory. Only values ​​from -2147483648 to 2147483647 can be kept inside int.

&#x20;Values ​​outside this range cannot be set to int. C uses 4 bytes of space in computer memory for int type. Since 1 byte = 8 bit, 4 byte means 32 bit (4 byte X 8 bit = 32 bit). Each 1 bit can hold 2 things, 0 and 1.

&#x20;4 numbers (00, 01, 10, 11) can be kept in 2 bit. Then it can be kept in 32 bit: 2^32 number i.e. 4294967296 number. Now if we put half positive and half negative, then the total number from -2147483648 to -1 is 2147483648 then from 0 to 2147483647 the total number is 2147483648, the total number is 4294967296. Can be kept.&#x20;

If you have trouble understanding the calculation, read it carefully once more, it will be clear.

### Adding program&#x20;

This time we will write a program to add the runs of 2 cricketers. Open [repl.it](https://replit.com/languages/c) in the browser as before. Then I write the following program and run it, then I will explain line by line.

```c
#include <stdio.h>
 int main()  
 {  
     int firstPlayer = 60;  
     int secondPlayer = 30;  
     int total;    
     total = firstPlayer + secondPlayer;  
     printf("Total score is %d", total);  
     return 0;  
 }  
```

After running the program you will see on the output screen on the right that:

![](https://1465263648-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MbVOMx7vQxI8sLy3t-c%2F-Mb_cK1V5FdX6CzxXM4k%2F-Mb_doIdjoQsZuwKceFQ%2Fimg-06.png?alt=media\&token=349b3d23-2fc1-4146-ad20-fc8f9561fcfa)

```c
Total score is 90
```

Here 2 int type variables named **`firstPlayer`** and **`secondPlayer`** are declared. In these 2 variables we have assigned values 60 and 30 respectively. After the previous chapters of the ebook, it is really easy to understand.

Then we declare a new variable called int total and assign the sum of **`firstPlayer`** and **`secondPlayer`** to it. That is, the value of total will be equal to the sum of **`firstPlayer`** and **`secondPlayer`** values.

&#x20;The next line is quite important. We have used the printf () function to display the sum on the monitor's output screen.

```c
printf("Total score is %d", total);
```

There are 2 parts inside the printf () function. In the first part, Total score is %d means that we want to print on the screen Total score is and an integer type value which will replace %d. Then we have written the total with a comma and explained that in %d, we have to print the value of total. As I used %d for integer type values, I have to write something else for other types of variables.&#x20;

For example, if we used the double type value we learned in the previous chapter, we would have to write %lf instead of %d. We learned about int type data. Now we will learn about some more important data types.

### float and double type data&#x20;

float and double are used to store real numbers or real number type values. These include 1, 47, 20.23, -11, -23.2, that is, decimal numbers or zero, positive or negative numbers.

```c
float length = 20;
double burgerPrice = 10.5;
```

Now the question is, what is the difference between float and double?&#x20;

* float can store 4 bytes of data and double is twice the amount of float, i.e. 8 bytes can store data.
* Just as we used %d for int type value, we use %f for float and %lf for double(lowercase L).

### char type data&#x20;

We declare character type data using the keyword char. E.g.

```c
char firstCharacter = 'A';
```

We use %c for char type data. Such as:

```c
 #include   
 int main ()  
 {  
     char firstLetter = 'A';
     printf("First letter of the Alphabet is %c", firstLetter);  
     return 0;  
 }
 
```

Output:

```c
First letter of the Alphabet is A
```

Note that char type data can store 1 byte amount of data.

### What we have learned in this chapter&#x20;

1. &#x20;int, float, double, char etc. are different data types.&#x20;
2. Each data type uses a different amount of data stores.
