Sunday, 12 February 2017

Variable and data types.

What is variable?
                      In programming a variable is nothing other than a name which is used to store some kind of data(information) this data needs some memory to be stored so we can say that variable is name of memory area. The data stored in the variable depends upon the type of data. To store the specific type of data you have to declare its type which is called as data type. Whenever we declare a variable it is stored in memory. When it is stored there it will have its specific address just like every house has its specific address in particular area. As, in real life address is very important for us same is the case in progamming. Progamming may be in assembly language or any high level language the address is very important. To store this address we need a specific type of variable which is called as pointer. We will discuss pointer later on. 
                         There are many data types in C++ which determines the size and layout of the variable's memory. Following are the data types in C++:


                                
                         Data type
                     
                        Size
               (1 byte= 8 bits)


int
4 bytes
float
4 bytes
double
8 bytes
long
4 bytes
char
1 byte
short
2 bytes
long float
8 bytes
further we will discuss later on.

As, we know that computer can understand only 0's and 1's. But we write a number e.g(3454) in our programme and we write sentences e.g('Hello world')etc. How they stored in memory?
First we talk about the integers or real numbers.
data type "int":
as the int data type has size of 4 bytes which means 32 bits. Maximum number which can be stored in this data type is:
232   -   1 =4294967295 (only when int is declared as unsigned)
Converting this number:
(4294967295)10 = (11111111111111111111111111111111)
this is the last number in 32 bits after that we will be entered in 33 bits which will be not reside as it is in our container means our variable data type.
e.g
232 =(4294967296)10 = (100000000000000000000000000000000)2

if we declare only int than it also includes singed integers which means negative number can be processed than its range is (-2147483647 to +2147483647)  which will be displayed as its is on console screen by Microsoft visual C++.

same method is applied for determining the range for other variables.











  

No comments:

Post a Comment