Friday, February 25, 2011

Data types & Type modifiers


Data types: int,float,char,double & void
The size and range of these data types may vary among processor types and compilers.


int: Size of int depends on length of a word of execution environment.In General int is 2 bytes for 16bit compiler.Int is used to store integer values.
eg: int a = 35 , int b.
If  b value is not specified, a memory of 2 bytes will allocated containing junk values

Float & Double: Float is used to store floating point values.The range of float and double will depend upon the method used to represent the floating point-point numbers.
eg: float b=35.6

Char:Char can be better called as byte for better understanding . As we know machine understands only binary values (0's and 1's) & we cant store character as it is in memory.
Eg: char a='A'


Now you may be wondering A is stored as 65(ASCII value of A) how will we able to get character when we give printf.This is were compiler comes into picture.Compiler does this job of converting ASCII to character.

Void:The type void either explicitly declares a function as returning no value or creates generic pointers.

Table below shows all data types defined by C standard

Type Modifier: A type modifier changes meaning of basic data type to fit specific needs.
Type modifiers are: Signed ,Unsigned,Long,Short

Signed: If an integer is specified as integer than compiler assumes high-order bit of an integer to used as sign flag.is sign flag is 0, the number is positive & if its 1,the number is negative .



Negative numbers are represented using the two's complement approach, which reverses all bits in the number (except the sign flag), adds 1 to this number, and sets the sign flag to 1.
Eg:32,776 in binary
0 1 1 1 1 1 1 1  1 1 1 1 1 1 1 0

1 comments:

Anonymous said...

The negative range specified in the chart is incorrect for most of the data type.

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger | Printable Coupons
Design Downloaded from Free Blogger Templates | Free Website Templates