Loading...

WHAT IS DATA TYPE – IMPORTANT TOPIC IN 2022

Hey guys, what is up. I hope you all are good and are doing quite well. In this particular post, we will be talking about what is the data type and type modifiers in C++.

WHAT IS DATA TYPE?

Data type helps us to know which type of data is it represents. It determines to identify the type of operations and data associated with it. 

There are 3 types of data types:

  1. Fundamental data types
  2. Derived data types 
  3. User-defined derived data types. 

FUNDAMENTAL DATA TYPE:

Those data types that are not composed of other data types are called fundamental data types. These are predefined in C++ and can be used directly.  

1. INTEGER (INT):

 It is defined with integer int. Integers are whole numbers. These data types have no fractional part. To declare a variable, we write: 

<data type> <variable name>; Example – int number;

  • The range of int datatype is from -32768 to +32767.
  • The size of int is two (2) bytes.

2. CHARACTER (CHAR):

It is defined with the keyword char. It is used to store characters in C++. These data types are often called integer data types as they are internally stored as integers by their ASCII value. To declare a variable, we write:

<data type> <variable name>; Example – char name;

  • The range of char is from -128 to +127 or 0 to 255
  • The size of the char datatype is one (1) byte.

3. FLOAT (FLOAT): 

A number having only a fractional part is a floating-point number. It is defined using the word float. To declare a variable using a float, we write –    

<data type> <variable name>; Example – float radius;

  • The range of float is from 3.4E-38 to 3.4E+38. 
  • The size of the float datatype is four (4) bytes.

ADVANTAGES OF FLOAT DATA TYPES OVER INTEGER DATA TYPES ARE:

  1. They represent fractional value
  2. They can represent a much greater value but they are much slower than integers.
  3. Floating-point numbers have 7 digits of precision and also show 6 digits after the decimal.

4. DOUBLE (DOUBLE):

They are also known as double-precision floating-point numbers. It is defined by the keyword double. Double is used similarly to that of the float data type. It is slower than float.

  • It handles floating point numbers with 15 digits of precision.
  • The range of double datatype is from 5.0 × 10−345 to 1.7 × 10308.
  • The size of double is eight (8) bytes. 

5. VOID: 

This datatype specifies an empty set of values and is used for return-type functions that do not return/restore any value. No object of type void can be declared.

DERIVED DATA TYPES:

Data types that are built from fundamental data types are called derived data types and these are not predefined. These are:

  • Array
  • Function 
  • Pointers
  • References 
  • Constants

USER-DEFINED:

Derived data types are defined by the user or programmers according to their needs and are known as user-defined derived data types. These are: 

  • Classes
  • Structure
  • Union 
  • Enumeration

DATATYPE MODIFIERS:

We use a modifier to change the size and value of the base data type to fit various situations more precisely. Fundamental data types except void can be modified using modifiers.

The list of modifiers are as follows:

  • Signed 
  • Unsigned
  • Long
  • Short

SIGNED:

It is the default float, char, and integers. It can store all real numbers that mean both positive and negative numbers.

UNSIGNED:

It is used with integer data types such as int and char. It doubles up the range of the positive side. Negative numbers are not acceptable.

LONG:

It can be used for both int and double data types. It increases the range and size of the variable. For example, Long int takes 4 bytes while long double takes 10 bytes.

SHORT:

Short is used with int data types. It is only a clarifier. It is similar to an integer.

SIZE OF ALL DATA TYPES:

TYPE SIZE (IN BYTES) MINIMAL RANGE
Char 1 -128 to 127
Unsigned char 1 0 to 255
Signed char 1 -128 to 127
Short 2 -32768 to 32767
Unsigned short 2 0 to 65,535
Signed short 2 -32768 to 32767
Int 2 -32768 to 32767
Unsigned int 2 0 to 65,535
Signed int 2 -32768 to 32767
Long 4 -2,147,483,648 to 2,147,483,647
Unsigned long 4 0 to 4,294,967,295
Signed long 4 -2,147,483,648 to 2,147,483,647
How to Start Looking for a New Job

Why Customers Love Us

What our customers say about us