Data Types in C++: int, float, double, char, and bool

Data Types in C++: int, float, double, char, and bool

In C++ programming language, particular data types are used to store and process data and information in multiple individual variable parameter values ​​declared in the program. Multiple data type values ​​defined in C++ programs manage and control the size of the parameter variable and the multiple operations that can be performed on that data type variable. C++ programming provides its users with several built-in data type methods and their types. These mainly include int for integral data type values, char for floating-data point type values, character data type and boolean data type by default.

Data Types in C++ int, float, double, char, and bool

So, let’s get to know the basic data types int, float, double, char, and bool in C++ programming.

Int Integer Data Type in C++.

Int Data Type Information – In C++ programs, the int data type is used to store and process complete integer data values ​​without any decimal point, including both positive and negative integer decimal numbers and numeric values ​​(only complete integer values).

Int Data Type Size – The int data type has a predefined and fixed size of 4 bytes (32 bits) in most used computer systems. However, it may vary depending on the default architecture of your current computer system. For example, it may be 2 bytes on a 16-bit system, 8 bytes on a 64-bit system, etc. depending on the system hardware.

Int Data Type Range – For a 4-byte int data type in a system, the default range is between -2,147,483,648 and 2,147,483,647. The actual and real range of the int data type depends entirely on your system’s architecture.

Example of an Integer Data Type.

int salary = 999; // Stores an integer data value named salary.

int national = -100; // Stores a negative integer value named national.

Modifier Int Data Types – C++ Programming Signed, Unsigned, Long, Short, etc. Data Types Any user-defined procedure in a program can modify the int type with these to represent a large or small data value range.

Unsigned int data type – Stores only positive numbers (0 and greater) in a C++ program.

Long int data type – Commonly used to store a large range of integer data values ​​in a C++ program.

The short int data type – Commonly used in C++ programs to store and process short integer data ranges.

float Floating-Point Data Type in C++.

float Data Type Information – In C++ programming, the float data type is mostly used to store and process single-precision floating-point numbers with floating fractional part data (floating numbers that have integer and decimal point numeric values ​​defined).

float Data Type Size – Generally, the default floating data type size in C++ programs is defined or fixed at 4 bytes (32 bits).

float Data Type Precision – In C++ programs, the float data type provides a precision of at least 6-7 decimal digits.

float Data Type Range – The storage range of the float data type in C++ programs is usually system-defined, from 1.5 × 10^−45 to 3.4 × 10^38 (for positive numeric values).

The floating data type precision in C++ programs has its own limitations, making it not a proper choice for large-scale or complete exact numeric data type processing.

Example of the float data type.

float pi_value = 3.14f; // Here the ‘f’ suffix represents a float literal data type value.

float temp = -98.3; // This stores a float data type value with the name temp.

Remember – Floating-point data types in C++ programs are normally easy to use because they represent numeric values ​​in binary format.

double – Double-Precision Floating-Point Data Type in C++.

double Data Type Description – The double data type is used in C++ programs to store and process double-precision floating-point numeric data values. They provide higher precision than floating point data types to represent actual real-time numeric value information in C++ programs.

double data type size – Generally, 8 bytes (64 bits) define the size of the double data type in C++ programs.

double data type precision – The double data type in C++ programs provides its user with a precision value of approximately 15-16 decimal digits.

double data type range – The range of the double data type in C++ programs is defined to be approximately 5.0 × 10^−324 to 1.7 × 10^308 (for positive decimal numeric values).

In C++ programs, the double data type is the perfect choice for exact real-time large-volume calculations and for managing and controlling very large or very small numeric data values.

Example of the double data type.

double pi_value = 3.141592653589793; // Here a double-precision floating-point value variable named pi_value is defined.

double national = 9.4e3; // This variable named national represents the scientific notation for 9.4 billion.

Remember – When you need to store and process high-precision exact data values ​​in a C++ program, you can use the double data type instead of the float data type. If you need an even larger data value range or for higher precision values, C++ users can use the long double data type.

char Character Data Type in C++.

Description of Character Data Type – In C++ programs, the char data type is used to store and process single-character text information (including characters, digits, symbols, or control characters) in the ASCII (American Standard Code for Information Interchange) character set or other character encoding text formats.

Character Data Type Size – In C++ programs, the char data type typically stores a 1 byte (8-bit) value.

Character Data Type Range – In C++ programs, the char data type can represent values ​​from -128 to 127 (for signed char value storage) or 0 to 255 (for unsigned char data values).

Example of a Character Data Type.

char score = ‘S’; // Here, the score variable, enclosed in single quotes, stores a single character value.

char alphabet = ‘p’; // This stores a lowercase character value, denoted by a p.

char specialop = ‘@’; // Here @ stores a special character value.

Character Data Type Modifiers – In C++ programs, char data type values ​​can be modified to store and process signed or unsigned data type values.

unsigned char Data Type – In C++ programs, the unsigned char data type has a default storage value of 0 to 255.

signed char Data Type – In C++ programs, the signed char data type stores character data values ​​from -128 to 127.

Remember – As in C++ programming, char is a built-in data type. Whereas in real-time programming, it is an integer data type. Because the char data type internally stores and represents the ASCII value of a character.

bool Boolean Data Type in C++.

Boolean Data Type Information – In C++ programs, the bool data type is used to store and process Boolean data values. Generally, the Boolean data type can have output values ​​of true or false.

Boolean Data Type Size – Generally, the Boolean data type is 1 byte (8 bits) in a C++ program, while the actual real Boolean data type size may vary depending on your current system hardware platform.

Boolean Data Type Range – Generally, the Boolean data type can represent only two values ​​in a C++ program. For example,

true – represents the value 1.

false – represents the value 0.

Example of the Boolean Data Type.

bool isReal = true; // Here the isReal variable is defined as true.

bool isFinal = false; // Here the isFinal variable is defined as false.

Use of the Boolean Data Type – In C++ programming, Boolean data type values ​​are mostly used in conditional statement values ​​like if, while, etc. to manage and control the current program flow control behavior order.

Detail information about c++ int, float, double, char, and bool Data Types

Data TypeData type DescriptionDefault SizeDefault Range (approx.)Each Example
Int data typeIt holds Integer type (whole numbers) data value in programHold 4 bytes in memory-2,147,483,648 to 2,147,483,647int p = 7;
Float data typeIt stores Single-precision floating-point data type value with fraction or mantissa partHold 4 bytes in memory±1.5 × 10^−45 to ±3.4 × 10^38float pi_value = 3.14f;
Double data typeIt holds Double-precision floating-point type with multiple precision valueHold 8 bytes in memory±5.0 × 10^−324 to ±1.7 × 10^308double pi_value = 3.14159;
Char data typeIt used to represent single Character data type valueHold 1 byte in memory-128 to 127 (signed) or 0 to 255 (unsigned)char letter = ‘V’;
Bool data typeBoolean type (true or false)Hold 1 byte in memorytrue or false (1 or 0) representationbool isValue = true;

Leave a Reply