Data Types in C Language
Data Types in C Language
In this tutorial you will learn about C language data types, Primary data type, Integer
Type, Floating Point Types, Void Type, Character Type, Size and Range of Data Types
on 16 bit machine, derived data type, Declaration of Variables, User defined type
declaration, Declaration of Storage Class, auto, static, extern, register, Defining Symbolic
Constants, Declaring Variable as Constant and Volatile Variable
A C language programmer has to tell the system before-hand, the type of numbers or
characters he is using in his program. These are data types. There are many data
types in C language. A C programmer has to use appropriate data type as per his
requirement.
1. Integer int
2. Character char
5. Void void
The size and range of each data type is given in the table below
Integers are whole numbers with a machine dependent range of values. A good
programming language as to support the programmer by giving a control on a range of
numbers and storage space. C has 3 classes of integer storage namely short int, int and
long int. All of these datatypes have signed and unsigned forms. A short int requires half
the space than normal integer values. Unsigned numbers are always positive and
consume all the bits for the magnitude of the number. The long and unsigned integers are
used to declare a longer range of values.
Floating point number represents a real number with 6 digits precision. Floating point
numbers are denoted by the keyword float. When the accuracy of the floating point
number is insufficient, we can use the double to define the number. The double is same as
float but with longer precision. To extend the precision further we can use long double
which consumes 80 bits of memory space.
Void Type :
Using void data type, we can specify the type of a function. It is a good practice to avoid
functions that does not return any values to the calling function.
Character Type :
A single character can be defined as a defined as a character type of data. Characters are
usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be
explicitly applied to char. While unsigned characters have values between 0 and 255,
signed characters have values from –128 to 127.
Declaration of Variables
Every variable used in the program should be declared to the compiler. The declaration
does two things.
Where v1, v2, v3 are variable names. Variables are separated by commas. A declaration
statement must end with a semicolon.
Example:
Int sum;
Character char
Signed Short Integer signed short int (or) short int (or) short
Signed Long Integer signed long int (or) long int (or) long