Data Types
Prepared by: Meet Thakar
Road map
• Introduction
• Data Type Modifiers
• Built-in Data Types
Prepared by: Meet Thakar
Introduction
Prepared by: Meet Thakar
Introduction
• The Computer stores various type of data in the main memory.
• Data types describe the type of data stored in the memory.
• C++ Data Types are divided into 3 categories:
1. Built-in Types:
• They are provided by C++
2. Derived Types:
• These types are derived from the Built-in Types.
3. User-defined Types:
• These types are created by the user (developer).
Prepared by: Meet Thakar
Introduction
Prepared by: Meet Thakar
Data Type Modifiers
Prepared by: Meet Thakar
Data Type Modifiers
• Allows adjusting the sizes and ranges of a data type.
• There are 4 data type modifiers:
• Sign-based:
• signed: Allows both positive and negative values.
• unsigned: Allows only positive values starting from 0.
• Size-based:
• short: Reduces the ranges and saves size in bytes.
• long: Expands the ranges, allowing bigger data to be stored but occupies
more memory.
• Note: A sign-based and a size-based modifiers can be combined.
Prepared by: Meet Thakar
Built-in Data Types: char
• Allows storing a single character.
• The value of a character type variable is surrounded by single inverted commas.
• A character may be an alphabet, a number or a special character.
• Example:
Type Size (16-bit) Range
char 1 -128 to 127
signed char 1 -128 to 127
unsigned char 1 0 to 255
Prepared by: Meet Thakar
Built-in Data Types: int
• int is short for Integer. Allows storing a non-fractional/complete number.
• Example:
Type Size (16-bit) Range
int 2 -32768 to 32767
signed int 2 -32768 to 32767
unsigned int 2 0 to 65535
short int 2 -32768 to 32767
short signed int 2 -32768 to 32767
short unsigned int 2 0 to 65535
long int 4 -2147483648 to 2147483647
signed long int 4 -2147483648 to 2147483647
unsigned long int 4 0 to 4294967295
Prepared by: Meet Thakar
Built-in Data Types: float
• Allows storing a floating-point (fractional) number.
• Example:
• The suffix “f” is necessary, if it’s not specified then it’ll be considered a double
floating-point number.
Type Size (16-bit) Range Digits of Precision
float 4 3.4e-38 to 3.4e+38 7
Prepared by: Meet Thakar
Built-in Data Types: double
• Allows storing a double floating-point (fractional) number.
• Example:
Type Size (16-bit) Range Digits of Precision
double 8 1.7e-308 to 1.7e+308 15
long double 10 3.4e-4932 to 1.1e+4932 18
Prepared by: Meet Thakar