A data type specifies the type of data a variable can store, for example, integer, floating point, character, etc. C++ supports the following data types:
These data types are built-in or predefined data types that the user can use to declare variables directly. These are:
| Integer | Boolean |
| Character | Double Floating Point |
| Floating Point | Wide Character |
| Valueless or Void |
Derived Data Types are data types that are derived from primitive or built-in data types. These can be classified into four types:
| Function | Array |
| Reference | Pointer |
These data types are specified by the user. The following user-defined datatypes are available in C++:
| Class | Structure |
| Union | Typedef defined Datatype |
| Enumeration |
Let’s take a look at fundamental data types. Its size is based on a 32-bit operating system.
| Data Types | Memory Size | Range |
|---|---|---|
| char | 1 byte | -128 to 127 |
| signed char | 1 byte | -128 to 127 |
| unsigned char | 1 byte | 0 to 127 |
| short | 2 byte | -32,768 to 32,767 |
| signed short | 2 byte | -32,768 to 32,767 |
| unsigned short | 2 byte | 0 to 32,767 |
| int | 2 byte | -32,768 to 32,767 |
| signed int | 2 byte | -32,768 to 32,767 |
| unsigned int | 2 byte | 0 to 32,767 |
| short int | 2 byte | -32,768 to 32,767 |
| signed short int | 2 byte | -32,768 to 32,767 |
| unsigned short int | 2 byte | 0 to 32,767 |
| long int | 4 byte | |
| signed long int | 4 byte | |
| unsigned long int | 4 byte | |
| float | 4 byte | |
| double | 8 byte | |
| long double | 10 byte |
An enumerated type specifies an optional type name as well as a set of zero or more identifiers that can be used as type values. Each enumerator is a constant of the enumeration’s type.
The keyword enum must be used when creating an enumeration. An enumeration type’s general form is
enum enum-name { list of names } var-list; For instance,
enum day(monday, tuesday, wednesday, thursday, friday) d; In C++, modifiers are used to change or add meaning to database types. It is used as a prefix to change the meaning of primitive data types. A modifier is used to alter the meaning of a basic type so that it better meets the needs of different situations. Following are the four datatype modifiers in C++,
Note: also read about the OOPs Concepts in C++
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
A design pattern is a reusable solution to a commonly occurring problem in software design. They…
Factory Method is a creational design pattern that deals with the object creation. It separates…
You are given two singly linked lists that intersect at some node. Your task is…
A builder plans to construct N houses in a row, where each house can be…
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…