Data Types in C
Data types in C : Data type is a classification of data that determines what type of data or value a variable can have or store (integer, floating, character, etc) and what will be size of the variable (1 byte, 2 bytes, etc). Data types are used to define variables in C programming. Each variable in C language has an associated data type and It can not store data or value of other data types except its associated data type.
For example :
Here, int is a data type and age is an int or integer data type variable. We can store or assign integer value in this variable but we can not store characters or floating numbers (14.12) in this variable because they are values of other data types. Size of this variable is 2 bytes (it can be different according architecture of systems and platforms).
What is data type in C?
As we know that you are able to answer of this question very easily now. In simple language, a data type is a way in C programming to specify that what type of data a variable can have.
C language mainly has four data types and they also have sub data types :
1 Primitive data types : Predefined or basic data types of C language are known as primitive data types like int, float, char, double, etc.
2 Derived data Types : A data type that is derived or built from primitive or basic data types for creating a new data type is called derived data type. In other words, it is aggregate of basic data types. Examples of derived data types are pointers, arrays, structures and unions. We will learn more about derived data types in coming sections.
3 Void data type : Void data type means no value or empty. It is used mostly with functions, when we do not want to return any value from a function.
4 Enumeration data Type : Enumeration data type is a special data type which is used to bind integer values (numbers) with names. It is also known as enum data type. We will learn more about enum data type in coming sections.
Primitive data types
int, char, float double, etc are the primitive or basic data types in C language. The primitive data types are integer-based and floating-point-based. We can use signed and unsigned literals in C language also.
int data type
int is an integer data type which is used to store integer value or whole number (14, 12, 1993, etc) but without decimal point like 14.012 .
Syntax of int data type variable
Example of int data type variable
Type, size and value range of standard integer data type are given below :
|Type||Size (In Byte)||Value Range|
|int||2 bytes||-32,768 to 32,767|
|signed int||2 bytes||-32,768 to 32,767|
|unsigned int||2 bytes||0 to 65,535|
|short int||2 bytes||-32,768 to 32,767|
|signed short int||2 bytes||-32,768 to 32,767|
|unsigned short int||2 bytes||0 to 65,535|
|long int||4 bytes||-2,147,483,648 to 2,147,483,647|
|signed long int||4 bytes||-2,147,483,648 to 2,147,483,647|
|unsigned long int||4 bytes||0 to 4,294,967,295|
float data type
float is a floating data type which is used to store float value or real number (14.12, 19.93, 10.01, etc).
Syntax of float data type variable
Example of float data type variable
Type, size and value range of standard float data type are given below :
|Type||Size (In Byte)||Value Range||Precision|
|float||4 bytes||1.2E-38 to 3.4E+38||6 decimal places|
|double||8 bytes||2.3E-308 to 1.7E+308||15 decimal places|
|long double||10 bytes||3.4E-4932 to 1.1E+4932||19 decimal places|
char data type
char is a character data type which is used to store single character ('V', 'k', etc).
Syntax of char data type variable
Example of char data type variable
Type, size and value range of standard char data type are given below :
|Type||Size (In Byte)||Value Range|
|char||1 byte||-128 to 127|
|signed char||1 byte||-128 to 127|
|unsigned char||1 bytes||0 to 255|
NOTE : The size of primitive data types can be variant according to 32 or 64 bits architecture of systems or platforms.