Data Types in C with examples and Size of Data Types
Data Types in C is very important concept to understand along with the size of Data Types in C. So In this article, I will be providing an information about Data Types in C with examples and Size of Data Types.
Data types refer to an extensive system used for declaring variables or functions of different types before its use. To represent different types of data in C program we need different data types.
The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The value of a variable can be changed any time.
C supports four different classes of data types namely:
Types of Data Types in C
Types | Data Types |
---|---|
Basic Data Type | int, char, float, double |
Derived Data Type | array, pointer, structure, union |
Enumeration Data Type | enum |
Void Data Type | void |
BASIC DATA TYPES in C
All arithmetic operations such as Addition , subtraction etc are possible on basic data types.
E.g.:
int a,b;
Char c;
The following table shows the Storage size and Range of basic data type:
Size of Data Types
Size is given according to 32-bit architecture.
Data Types | Memory Size | Range |
---|---|---|
char | 1 byte | −128 to 127 |
signed char | 1 byte | −128 to 127 |
unsigned char | 1 byte | 0 to 255 |
short | 2 byte | −32,768 to 32,767 |
signed short | 2 byte | −32,768 to 32,767 |
unsigned short | 2 byte | 0 to 65,535 |
int | 2 byte | −32,768 to 32,767 |
signed int | 2 byte | −32,768 to 32,767 |
unsigned int | 2 byte | 0 to 65,535 |
short int | 2 byte | −32,768 to 32,767 |
signed short int | 2 byte | −32,768 to 32,767 |
unsigned short int | 2 byte | 0 to 65,535 |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
signed long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 byte | 0 to 4,294,967,295 |
float | 4 byte | 3.4*10E-38 to 3.4*10E38 |
double | 8 byte | 1.7*10E-308 to 1.7*10E308 |
long double | 10 byte | 3.4*10E-4932 to 1.1*10E4932 |
Now, next data types in C.
DERIVED DATA TYPES in C
Derived datatypes are used in ‘C’ to store a set of data values. Arrays and Structures are examples for derived data types.
Ex:
int a[10];
Char name[20];
USER DEFINED DATATYPES in C
C Provides a facility called typedef for creating new data type names defined by the user. For Example ,the declaration.
typedef int Integer;
Makes the name Integer a synonym of int.Now the type Integer can be used in declarations ,casts,etc,like,
Integer num1,num2;
Which will be treated by the C compiler as the declaration of num1,num2as int variables. “typedef” ia more useful with structures and pointers.
POINTER DATA TYPES in C
Pointer data type is necessary to store the address of a variable.
Comments
Post a Comment