Data Types
Data Types
A data type is used to indicate the type of data value stored in a variable.
A data type is essential to identify the storage representation (How much memory
allocates) and the type of operations that can be performed on that data.
There are three classes of data types:
1. Primary Data types
2. Derived Data types
3. User Defined Data types
Size in Minimal
Data Type Bytes Range Format Specifier
char 1 -27 to 27-1 %c
unsigned cha
r 1 0 to 28-1 %c
signed char 1 -27 to 27-1 %c
Integer Type:
It is used to store whole numbers. These numbers do not contain the decimal
part.
integers stored in 16 bits or 2 byte of memory.
integers can also be signed and unsigned.
Its format specifier is %d.
Its range is -215 to 215-1
Size in
Type Bytes Minimal Range Format Specifier
int 2 -(215 - 1) to 215 - 1 %d, %i
unsigned int 2 0 to 216 - 1 %u
signed int 2 -(215 - 1) to 215 - 1 %d, %i
short int 2 -(215 - 1) to 215 - 1 %hd
unsigned short int 2 0 to 216 - 1 %hu
signed short int 2 -(215 - 1) to 215 - 1 %hd
long int 4 -(231 - 1) to 231 - 1 %ld, %li
long long int 8 -(263 - 1) to 263 - 1 %lld, %lli
signed long int 4 -(231 - 1) to 231 - 1 %ld, %li
unsigned long int 4 0 to 232 - 1 %lu
unsigned long long int 8 0 to 264 - 1 %llu
Float Type:
Double floating point data type occupies 8 bytes of memory giving 14 digits
of precision. These are also known as double precision numbers. Variables
are declared by keyword double. . Its format specifier is %lf
long double refers to a floating point data type that is often more precise
than double precision. . Its format specifier is %Lf
Void type The void type has no values. This is usually used to specify the return
type of functions. The type of the function said to be void when it does not return
any value to the calling function. This is also used for declaring general purpose
pointer called void pointer.
Derived data types Derived datatypes are used in ‘C’ to store a set of data values.
Arrays , Structures , Union and pointer are examples for derived data types.
User-defined data types: The data types defined by the user are known as the
user-defined data types. C provides two identifiers typedef and enum to create new
data type names.
EX:
#include <stdio.h>
void main()
{
char ch='k';
int a=33;
float b= 2.135;
double c=4.8967;
printf("\ncharcter = %c",ch);
printf("\nInteger = %d",a);
printf("\nFloat = %f",b);
printf("\nDouble = %lf",c);
}