
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Data types ranges and their macros in C++
Given the task is to find the memory range of the different data types, that what range of value a data type can store the value from minimum value to maximum value. There is memory range of data type from in which value of data can be stored. It is difficult to remember the large range of value so C++ has macros for represent these numbers, from macros these large numbers can be directly assigned to variable without typing the whole Number range.
Example
‘char’(signed) is character data type and has a range of -128 to +128 and macro for minimum value, macro to find the range values of char data type is CHAR_MIN and CHAR_MAX.
Likewise we can find range of any data type by these MIN and MAX macros like for ‘int’ we can use INT_MIN and INT_MAX.
Range of char
128 to +128
Range of int
-2147483648 to +2147483648
Example
C++ code to demonstrate the macros of data types
#include<iostream.h> #include<float.h> #include<limits.h> Using namespace std; int main( ) { cout<< " Range of Char :” << CHAR_MIN<< " to ”<<CHAR_MAX; cout<< " Range of int :” <<INT_MIN<< " to " <<INT_MAX; cout<< " Range of float :” <<FLT_MIN<< " to " <<FLT_MAX; cout<< " Range of double :” <<DBL_MIN<< " to " <<DBL_MAX; cout<< " Range of short char :” <<SCHAR_MIN<< " to " <<SCHAR_MAX; cout<< " Range of Unsigned Char :” << 0 << " to " <<UCHAR_MAX; cout<< " Range of long int :” <<LONG_MIN<< " to " <<LONG_MAX; cout<< " Range of Unsigned int :” << 0 << " to " <<UINT_MAX; cout<< " Range of short int :” <<SHRT_MIN<< " to " <<SHRT_MAX; cout<< " Range of float Negative :” <<-FLT_MIN<< " to " <<-FLT_MAX; cout<< " Range of double negative:” <<-DBL_MIN<< " to " <<-DBL_MAX; Return 0; }
Output
If we run the above code it will generate the following output −
Range of char: -128 to 127 Range of int: -2147483648 to 2147483648 Range of float: 1.17549e-38 to 3.40282e+38 Range of double: 2.22507e-308 to 1.79769e+308 Range of Short char: -128 to 127 Range of Unsigned Char: 0 to 255 Range of long int: -922337203685477580 to 922337203685477580 Range of Unsigned int: 0 to 42944967295 Range of Short int: -32768 to 32767 Range of float negative: -1.17549e-38 to -3.40282e+38 Range of double negative: 2.22507e-308 to 1.79769e+308
- Related Articles
- Data Type Ranges and their macros in C++
- Macros and Preprocessors in C
- Internet Cookies and Their Types
- Average Data in Multiple Non-Contiguous Ranges in Excel
- Difference between fundamental data types and derived data types in C++
- Variables, their types, and Scope in C++
- Difference between Fundamental data types and derived Data Types
- What are Heterotrophs and their types?
- What are crops, and their types?
- What are polygons and their types?
- Flip-flop types and their Conversion in C++
- Hygienic Macros in C
- Multiline macros in C
- What are the data types, value types and reference types in C#?
- Types of DBMS Entities and their examples
