Data Types in C

View

Variables- Variable is an identifier used to store values in it. For example – a,b,c, etc. A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines-

  1. the size and layout of the variable's memory;
  2. the range of values that can be stored within that memory;
  3. and the set of operations that can be applied to the variable.

Data Types- Each variable that we declare in a C program must have a data type. Data type tells-

  1. Size of space occupied by that variable.
  2. Type of value that can be stored in that variable.
  3. Range of value that can be stored in that variable.
  4. Format specifier (how C will recognize the data type of variable)

In C, there are 3 categories of data types-

  1. Integer types
  2. Floating point types
  3. Character Types

Integer types-

(i) int or signed int or short
Space-                                           2 bytes
Type of value-                                Integer type
Range-                                           -32768 to +32767
Format specifier-                           %d

(ii) unsigned int or unsigned short
Space-                                           2 bytes
Type of value-                                Integer type
Range-                                           0 to +65535
Format specifier-                           %ud

(iii) long or long int or signed long int
Space-                                           4 bytes
Type of value-                                Integer type
Range-                                           -2,147,483,648 to +2,147,483,647
Format specifier-                           %ld

(iv) unsigned long or unsigned long int
Space-                                           4 bytes
Type of value-                                Integer type
Range-                                           0 to + 4,294,967,295
Format specifier-                           %lu

Floating Point types-

(i) float
Space-                                           4 bytes
Type of value-                                Real type
Range-                                           -3.4E-38 to +3.4E+38
Format specifier-                           %f

(ii) double
Space-                                           8 bytes
Type of value-                                Real type
Range-                                           -1.7E-308 to +1.7E+308
Format specifier-                           %lf

(iii) long double
Space-                                           10 bytes
Type of value-                                Real type
Range-                                           -3.4E-4932 to +1.1E+4932
Format specifier-                           %Lf

Character types-

(i) char or signed char
Space-                                           1 byte
Type of value-                                Character type
Range-                                           -128 to +127
Format specifier-                           %c

(ii) unsigned char
Space-                                           1 byte
Type of value-                                Character type
Range-                                           0 to +255
Format specifier-                           %c

Last modified: Tuesday, 21 September 2021, 9:36 AM