You are on page 1of 6

Data Types

A data type in C programming language declares the type of data that a variable
can store and how much memory is required to store this data.

 Primary Data Type/Built-in/fundamental/Primitive/Basic


 Derived Data Type
 User Defined Data Type

C Basic Data Types


There are four basic data types in C programming language.

 Character (char)
 Integer (int)
 Floating Point (float)
 Double Floating Point (double)

All other data types are derived from these basic data types.
The size of basic data types are machine dependent, For example size of an integer
data type in a 32 bit computer is 4 bytes whereas size of integer data type in 16 bit
computer is 2 bytes. To know the exact size of any data type, we should
use sizeof operator.

Integer Data Type

Integer data type is used to store a value of numeric type. Memory size of a variable of
integer data type is dependent on Operating System, For example size of an integer
data type in a 32 bit computer is 4 bytes whereas size of integer data type in 16 bit
computer is 2 bytes.
Keyword int is used to declare variables of type integer. Range of integer(int) data
type in 16 Bit system is -32,768 to 32,767.
For Example
int i = 2015;
Above statement declares a variable 'i' of integer data type and stores 2015 in it's
memory location.

For example : A variable of int type requires 2 bytes (= 2 x 8 = 16 bits). Out of this,
1 bit is reserved for sign (-or+) and remaining 15 bits can contain 0 or 1. So the range
of values supported will be -215 (-32768) to +215-1 (+32767).

The following table, shows the different basic data types, their size and value range in
a 16 bit operating system.

Character Data Type

Character data type is used to store a character. A variable of character data type
allocated only one byte of memory and can store only one character. Keyword char is
used to declare variables of type character. Range of character(char) data type is -128
to 127.
For Example

char c = 'A';
Above statement declares a variable 'c' of character data type and stores character 'A'
in it's memory location.

C Data Type Modifiers

Modifiers in C specifies the amount of memory space to be allocated for a variable.


Modifiers are prefixed with basic data types to modify the amount of memory
allocated for a variable.
For Example in a 16 bit system, the size of int data type is 2 bytes. If we add long
prefix in integer variable declaration(long int), it's size becomes 8 bytes.

There are five data type modifiers in C Programming Language:


 long
 short
 signed
 unsigned

Integer Data Type Variations


 int or signed int
 unsigned int
 short int or short signed int
 unsigned short int
 long int or signed long int

 unsigned long int

Floating Point Data Type

Floating point data type can be sub-divided into two types on the basis of precision
and size.

float 4 bytes with six digits of precision

double 8 bytes with sixteen digits of precision


float data type

Floating point data type in C is used to store a value of decimal values. Memory size
of a variable of floating point data type is dependent on Operating System, For
example size of an floating point data type in a 16 bit computer is 4 bytes. Keyword
float is used to declare variables of floating point type. Floating point data type
provides up-to 6 digits of precision.

For Example

float f = 11.243567;
Above statement declares a variable 'f' of float data type and stores 11.243567 in it's
memory location.

double data type


Floating point data type similar to float data type except it provides up-to sixteen digit
of precision and occupies eight bytes of memory.

For Example

double d = 11676.2435676542;

Above statement declares a variable 'd' of double data type and stores
11676.2435676542 in it's memory location.
All C compilers support four fundamental data types

Type Range of Description


values

char -128 to 127 a single byte(8 bits) and can store one character type
(Characters) data

int -32768 to an integer type is used to represent whole numbers


Integers (whole 32767 within a specified range of values.
numbers)

float 3.4e-38 to single-precision floating point


Floating point 3.4e+38
(real numbers)

double 1.7e-308 to double-precision floating point


(Double) 1.7e+308
The following table shows the size and range of the type-specifiers on most
common implementations :

Type Size(bits) Range

char or signed char 8 -128 to 127

unsigned char 8 0 to 255

int or signed int 16 -32768 to 32767

unsigned int 16 0 to 65535

short int or signed short int 8 -128 to 127

unsigned short int 8 0 to 255

long int or signed long int 32 -2147483648 to 2147483647

unsigned long int 32 0 to 4294967295

float 32 3.4E-38 TO 3.4E+38

double 64 1.7E-308 TO 1.7E+308

long double 80 3.4E-4932 TO 1.1E+4932

You might also like