Data Types, Variables and Constants

Concept of Data Types

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

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 :

  1. Int – includes all whole numbers (Eg. 1, 456, 8643)
  2. Char – includes all characters (Eg. Letter, Number, Space, Symbol)
  3. String – comprises of a set of characters (Eg. Hello Sumit, How are you)
  4. Float – contains decimal point numbers (Eg. 9.1, 2.655463. 3.1428571, 1.0)
  5. Double – stores fractional numbers (Eg. 2.34, -1.145)
  6. 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.

  1. Int
  2. Char
  3. Float
  4. Double
  5. Boolean

User-Defined Type

These Data Types are defined by the users in the program as per their needs.

  1. Structure
  2. Array
  3. Class
  4. Enumeration
  5. Union

Composite/Derived Type

These data types are formed by using basic data types i.e. using one or more built-in data types.

  1. Array
  2. Function
  3. Pointer
  4. Record
  5. Set

FAQs on Data Types

Q1. What is the size of a char data type?

  1. 4 bits
  2. 16 bits
  3. Depends on the system/compiler
  4. 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?

  1. Array
  2. Function
  3. Union
  4. 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?

  1. Int
  2. Float
  3. Struct
  4. Double

Answer: Option C, The size of the structure depends on its fields.

Share with friends

Customize your course in 30 seconds

Which class are you in?
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
Ashhar Firdausi
IIT Roorkee
Dr. Nazma Shaik
Gaurav Tiwari
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.