Memory capacity of various datatypes in C | Programming tutorials | C programming | C programming tutorials

Hello friends, As we have discussed in the previous article that there are various data types in the C language. Each data type has a different memory capacity in the computer memory, which means each value of a specific data type accommodates a particular memory size in the computer memory.

As all of us know that there are several memory units in the computer systems and the smallest of which is a bit. The different memory units and their sizes are given below:-


                                1 byte = 8 bits
                                1 kilobyte = 1024 bytes
                                1 megabyte = 1024 kilobytes
                                1 gigabyte = 1024 megabytes
                                1 terabyte = 1024 gigabytes
                                1 petabyte = 1024 terabytes

Any data type in the C language stores its value in the memory unit called bytes. We have given the memory capacity of each datatype below:-

1. Integer:- 
                        
An integer variable occupies a memory size of 2 bytes or 4 bytes depending on the compiler that you are using. However, in most of the compilers int and long int occupies a memory size of 4 bytes whereas, short int occupies a memory size of 2 bytes in the computer memory. 


for example,    int x = 46748839;   In this example, the variable ' x ' is of int data type, so the variable occupies a memory size of 4 bytes in the computer memory. 

2. Character:-

A character variable usually occupies a memory size of only 1 byte in the computer memory.

for example, char C = 'a';     In this example, The variable ' C ' is of character datatype so the variable occupies only 1 byte in the computer memory.


3. Float:-

A float variable occupies a memory size of 4 bytes in the computer memory.

for example, float f = 10.9;   In this example, The variable ' f ' is of float datatype so the variable occupies only 4 bytes in the computer memory.

4. Double:-

A double variable occupies a memory size of 8 bytes in the computer memory.



for example, double d = 190.985975892;   In this example, The variable ' d ' is of double datatype so the variable occupies 8 bytes in the computer memory.


That's all for now guys, we have completed the memory capacity of each datatype in the C language. And now we have understood what are variables and how do they store data in the computer memory.

In our next article, we will learn about the ASCII system of characters which will be very interesting to learn. If you have any suggestion / Advice for us, feel free to let us know in the comment section. We will be happy enough to know your feedback. Also, your appreciation will motivate us to add more to this blog.

Till then, Stay safe & Stay healthy. Have a nice day!!





Comments