Datatype in C

A datatype is a reserve word / user defined that is responsible to allocates memory space and it specifies following two properties:-
(i)                  It specifies capacity of memory space in byte.

(ii)                It specify type of memory space.

NOTE:

0/1= 1 bit
4 bit=1 nibble
8 bit=1 byte
1024 byte=1 KB
1024 KB= 1 MB
1024 MB=1GB
1024 GB=1 TB

[KB=Kilo Byte, MB= Mega Byte, GB=Gigabyte, TB=Terabyte]
The C compiler provides 5 datatype these are:-
datatype                                  size(in bytes)                           type
void                                                     0                      non return type
char                                                     1                      one character
int                                                        2                      round integer
float                                                     4                      fractional
double                                                 8                      fractional

1)      void:- A void datatype doesnot allocates memory space. So,it doesnot use for defines for variable. A void is used with pointer or function.

2)      char:- A variable define by char datatype allocates 1 byte memory space and it can store ASCII value of only one character at a time.
Example:- char ch;
(i)                 ch = A;  ×
Note:-A character must be enclosed within single quotes where single quotes (‘ ‘) is responsible to drop ASCII values.
(ii)               ch = ‘A’;
or
ch= 65;
(iii)             ch= ‘AB’;
[two character is special character with escape single character as treat as single character. Example:- \n,\r,\t are escape sequence character.]
NOTE:- A single quotes(‘ ‘) allowed one or two character due to escape sequence character because an escape sequence character is a special character that made by merging two character but it internally treated as single character.
Example:- ch = ‘\r’;
(iv)              ch= ‘ABC’; ×
(v)                ch= ‘A’ +32;
[It will store A’s ASCII value i.e 65.So ch will store 65 + 32=97.]
(vi)              ch =’a’ -30;
 [It will store a’s ASCII value i.e 97.So ch will store 97 - 30=67.]

      3)      int:- A variable defined by int datatype allocates 2 bytes memory spaces and it allocated 0-9 digits, hyphen(-).

Example:- int a;
a= 20; √                                         a= A; ×
a= -20; √                                        a= ‘A’; √
a= +20; √                                       a=’b-30’; √
a=45.37; √

       4)      float:- A variable defined by float datatype allocates 4 byte memory space and it store a fractional value. A float type variable allowed 0-9 digits, hyphen(-), period(.).
Example:- float num;
(i)                 num=45.87;
(ii)               num = -45. 87;
(iii)             num= + 45.87;
(iv)              num = 25; [ it will store 25.00 in variable num]
(v)                num=45.87f;

       5)      double:-  A variable define by double datatype allocates 8 bytes memory spaces and it also stores fractional value. A double datatype allowed 0-9 digits, hyphen(-), period(.).
Example:- double num;
(i)                 num= 45.78;
(ii)               num= -45.78;
(iii)             num = + 45.87;
(iv)              num=45; [it will store 45.00 in memory].

Comments

Popular Posts