Vous êtes sur la page 1sur 3

Data Types in C

Data types are basically the types of data that can be used for storage purposes in the program. C is rich
in data types. A data type is defined as a finite set of values along with well defined rules for operations
that can be performed on these values.

int
It is the integer data type used to store integer values such as 5, -6, 12 & so on. It can be divided into
six parts:-
signed int: used to store +ve as well as -ve integers
unsigned int: used to store only +ve integers
signed short int: used to store +ve and -ve integers with a smaller storage capability than signed int
unsigned short int: used to store only +ve integers with a smaller storage capability than unsigned int
signed long int: used to store +ve and -ve integers with a larger storage capability than signed int
unsigned long int: used to store only +ve integers with a larger storage capability than unsigned int
char
It is the character data type used to store characters such as 'v', 'F', '(' & so on. It is classified under the
integral data type as the storage occurs in the form of ASCII values which are used to represent every
character. The ASCII table is provided as a separate topic.

float
It is used to store floating type variables such as 12.34, 2.4 & so on.

double
It is also used to store floating type variables but with a greater storage capability.

TYPE SIZE(in bytes) RANGE


signed int 2 -27 to 27-1
unsigned int 2 0 to 28-1
signed short int 1 -128 to 127
unsigned short int 1 0 to 255
signed long int 4 -231 to 231-1
unsigned long int 4 0 to 232-1
char 1 0 to 255
float 4 3.4*10-38 to3.4*1038
double 8 1.7*10-308 to 1.7*10308
long double 10 3.4*10-4932 to 1.1*104932

void
As the name indicates this type has no values. Most of the times it is used so as to indicate that a
function does not return any value.

User defined
These types of data types are generally to be defined by the user itself. For example structures, unions
and enumerated types which we discuss in the next few topics.

Derived
The derived data types are pointers, functions and arrays which we will discuss in next topics.
Conversion characters
Conversion characters are used to represent each data type and are used int the input or output
statements. Each data type has a conversion character.

signed int, signed short int & signed long int use %d.
unsigned int, unsigned short int & unsigned long int use %u.
char uses %c.
float uses %f, %e or %g.
double uses %le or %lg.
Long double uses %Lf, %Le or %Lg.

Volatile variables
The qualifier 'volatile' is used to tell the compiler that a variable's value may be changed at any time by
some external sources.

volatile int date;

Here, the value of the integer variable will be altered by some external factors even if it does not appear
on the left hand side of an assignment statement. However, the value of a variable declared as volatile
can be modified by its own program as well.

Vous aimerez peut-être aussi