1.int
2.float
3.char
4.double
5.void
i am going to discuss about 4 of them(first four) under this section..and this discussion is on the issues such as memory, maximum value, minimum value etc.,
Before going to discuss about the variable i guess every one are aware of the bytes, bits and the memory terminology....
1 byte= 8 bits
1 kilo byte=1024 bytes
1 mega byte=1024 kilobytes
1 giga byte= 1024 megabytes
i guess this information is necessary for the basics of c-programming
1. int
int is a data type in which only integer values can be stored like 3,6,10,1098 etc.,and the information should not be like 10.9,a,acb etc.,
Memory used:
coming to memory section the total memory storage of this integer is 2bytes i.e, 2*8 bits(16 bits)
i.e., if the statement is like this
int a;
then this statement means that 'a' is an integer type of variable and for it to create in the memory it needs 2bytes of storage.
Max and Min value
By default int a; is an signed integer...signed integer uses an extra bit to determine its sign....so only 15 bits are used to give the information..
the MSB bit is used to determine the sign of the number...for a negative number 1 is at MSB and if there is 0 at the end then its a positive number...so the maximum number that an inter can solve is
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
this when reduced from the binary to the original value then it would become +32767
similarly the least number that an integer can store is as follows
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
which is negative... -32767
2. Char
Data type which is used to store a character into memory
Memory Used
character variable takes one byte of memory...ie 8 bits
hence the maximum value of a character would be something like this
0 1 1 1 1 1 1 1
which comes to 127 and the minimum number in the same way
1 1 1 1 1 1 1 1
comes to -127
these characters are stored in ASCII format i would explain one character and go through the text for complete reference....
like 'a' variable has an ascii value of 97 so first 97 is converted to binary format and stored as the binary number
0 1 1 0 0 0 0 1
i guess u got an idea of how the values are stored in C-Programming....
In the similar lines float and double values will be stored float values can store decimal information while double values can store both the integers and decimals as well...the memory for float is 4 bytes(32 bits) and for double is 8 bytes(64 bits) and the maximum and minimum value these variables are stored are found out in the similar way....i just gave the brief idea of the variables for using them in programming..would give u a detail description further as the blog proceeds....
Qnts
1. What is the maximum value that a double can store?
2. how the character 'u' can be stored?
3. int a;
float b;
char c;
what is the amount of memory for these initialisations????
you can give answers in the form of comments????
No comments:
Post a Comment