In the programming world, Data Type is the set of quantities that belongs together and are of a similar category. Data type is used so that the compiler or interpreter of a programming language can be told about the data which is to be used. The compiler also allocates the required amount of memory storage as per the data type defined thus saving space. Let us dive deep into the article to understand more about the concept of Data Type.
Definition of Data Types
Data Types or Types are attributes that are predefined or can be created by the user so that the program can easily detect the different types of information. This is useful because Computers can understand only Binary Language i.e. 0’s and 1’s. To perform other basic and complex math operations, you need Data Types that will be understandable in computer language.
Data Types tells the Memory Management Unit (MMU) how much memory is required to store the data before the program compiles.
Each Data Type has a memory size that is pre-defined by the programming language. For example, In Java programming language :
Type | Size |
Boolean | 1 bit |
Char | 16 bits |
Int | 32 bits |
Float | 32 bits |
Double | 64 bits |
Real-life Example of Different Data Types Used
A student login system might require attributes such as Student Name, Age, Birth Date, Roll Number, Address, Class, Division, Time of Login, Mobile Number, etc. Each variable needs to be stored and segregated according to their Data Types during coding to inform the compiler about the expected input data. This will be helpful to classify what type of data does the system contains and it will be easier to work on that.
Browse more Topics Under Data Types, Variables and Constants
- Built-in Data Types
- Constants in Programing LanguageÂ
- Access Modifier
- Variables of Built-in-Datatypes
- Declaration/Initialization of Variables
- Assignment Statement
- Type Modifier
Different Data Types
Many programming languages have their own pre-defined data types which can be used by simply typing the keywords assigned to them. Few programming languages have their own different Data Types and their characteristics are unique.
Basic Data Types :
- Int – includes all whole numbers (Eg. 1, 456, 8643)
- Char – includes all characters (Eg. Letter, Number, Space, Symbol)
- String – comprises of a set of characters (Eg. Hello Sumit, How are you)
- Float – contains decimal point numbers (Eg. 9.1, 2.655463. 3.1428571, 1.0)
- Double – stores fractional numbers (Eg. 2.34, -1.145)
- Boolean – contains one of 2 possible values only. (Eg. True or False)
Classification of Data Types
Built-in Type/Primitive Type
Data Types that are pre-defined and provided by each Programming Language.
- Int
- Char
- Float
- Double
- Boolean
User-Defined Type
These Data Types are defined by the users in the program as per their needs.
- Structure
- Array
- Class
- Enumeration
- Union
Composite/Derived Type
These data types are formed by using basic data types i.e. using one or more built-in data types.
- Array
- Function
- Pointer
- Record
- Set
FAQs on Data Types
Q1. What is the size of a char data type?
- 4 bits
- 16 bits
- Depends on the system/compiler
- Cannot be determined
Answer: Option C. Size of the data type is different for different programming languages and is decided by the system.
Q2. Which of the following is a built-in data type?
- Array
- Function
- Union
- Float
Answer: Option D, Other options are User-defined data types and composite data types.
Q3. Which data type has a size that is variable?
- Int
- Float
- Struct
- Double
Answer: Option C, The size of the structure depends on its fields.
Leave a Reply