MAP

DATA TYPES IN C


C language has very rich set of data types. At presently we will go through some of the basic data types available in C.

Variable Type
Keyword
Bytes
Required
Range
Format
Character
(Signed)
Char
1
-128 to +127
%c
Integer
 (Signed)
Int
2
-32768 to +32767
%d
Float
(Signed)
Float
4
-3.4e38 to +3.4e38
%f
Double
Double
8
-1.7e308 to + 1.7e308
%lf
Long integer
(Signed)
Long
4
-2,147,483,648 to 2,147,438,647
%ld
Character
 (Unsigned)
Unsigned char
1
0 to 255
%c
Integer
 (Unsigned)
Unsigned int
2
0 to 65535
%u
Unsigned long integer
Unsigned long
4
0 to 4,294,967,295
%lu
Long double
Long double
10
-1.7e932 to +1.7e932
%Lf

Character:

 To access and to store single character it use char data type in C. Char data type occupies  1 bytes. It means that char data type use 1 byte of memory to store some character value.

Declaration of character variable:
char ans;       
Assigning values to character variable:
Ans=’y’;

8          7          6          5          4          3          2          1
Sign







27         26         25         24         23         22         21         20

Above given is a general structure of character variable. The leftmost bit is used to indicate the positive or negative value of a variable. So the range for character variable is –27 to 27 –1 .means –128 to 127.

Integer:

 To access and to store any integer value int data type is use. C’s int data type occupies 2 bytes in the memory.
To declare any integer variable:
Int rollno;
Int accno;
To assign or to store integer value in this variable:
Rollno=10;
Accno=100;
16   15   14    13   12   11    10   9     8      7     6     5     4     3     2      1
Sign















215    214   2 13    212   211    210   2 9      2 8    27      26     25       24     2 3      22     21     20

Above given is a general structure of integer variable. The leftmost bit is used to indicate the positive or negative value of a variable. So the range for integer variable is –215 to 215 –1 .means –32768 to 32767.

Float:

To access and to store any real value float data type is use. C’s float data type occupies 4 bytes in the memory.

To declare any float variable:
Float per;
Float rate;
To Assign or to store some real value
Per=70.20;
Rate=123.45
32                                                                                                                                               1
Sign































231                                                                                                                                                                                               20
Above given is a general structure of float variable. The leftmost bit is used to indicate the positive or negative value of a variable. So the range for float variable is –231 to 231 –1 .
Means -3.4e38 to +3.4e38

Long:

To access and to store any integer value long data type is use. C’s long data type occupies 4 bytes in the memory.
To declare any long variable:
long account;
long price;
To Assign or to store some long value
account=123456;
Rate=98765;
32                                                                                                                                               1
Sign































231                                                                                                                                                                                               20
Above given is a general structure of long variable. The leftmost bit is used to indicate the positive or negative value of a variable. So the range for long variable is –231 to 231 –1 .
Means - 2,147,483,648 to +2,147,438,647

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More