Home » C++ programming language

<climits> (limits.h) Macro constants of (sizes of integral types) in C++

C++ <climits> (limits.h) macro constants of (sizes of integral types): Here, we are going to learn about the Macro constants of (sizes of integral types) which are defined in climits header and limits.h header file in C++.
Submitted by IncludeHelp, on May 03, 2019

C++ Macro constants of (sizes of integral types)

In this tutorial, we are learning about some of the defined macro constants which are used to find the sizes of the integral types like a character, short, integer, long integer, long long integer. These macro constants are used to find the minimum and maximum size of any integral type of data type.

These macros are defined in <limits.h> header file and <climits> header (for C++ 11).

List of Macro constants in C++

Here, is the list of the macro constants that can be used to find the sizes, minimum and maximum values of the specific integral data types.

Macro constant Description Value*
CHAR_BIT It returns the number of its in a char object. 8
SCHAR_MIN It returns the minimum value of a signed char object. -128
SCHAR_MAX It returns the maximum value of a signed char object. 127
UCHAR_MAX It returns the maximum value of an unsigned char object. 255
CHAR_MIN It returns the minimum value of a char object. 0 or SCHAR_MIN
CHAR_MAX It returns the maximum value of a char object SCHAR_MAX or UCHAR_MAX
MB_LEN_MAX It returns the maximum number of bytes in a multibyte character, for any locale 1 or greater
SHRT_MIN It returns the minimum value of a signed short int object. -32768
SHRT_MAX It returns the maximum value of a signed short int object. 32767
USHRT_MAX It returns the maximum value of an unsigned short int object. 65535
INT_MIN It returns the minimum value of a signed int object. -32768 or -2147483648
INT_MAX It returns the maximum value of a signed int object. 32767 or 2147483647
UINT_MAX It returns the maximum value of an unsigned int object. 65535 or 4294967295
LONG_MIN It returns the minimum value of a signed long int object. -2147483648 or -9223372036854775808
LONG_MAX It returns the maximum value of a signed long int object. 2147483647 or 9223372036854775807
ULONG_MAX It returns the maximum value of an unsigned long int object. 4294967295 or 18446744073709551615
LLONG_MIN It returns the minimum value of a signed long long int object. -9223372036854775808
LLONG_MAX It returns the maximum value of a signed long long int object. 9223372036854775807
ULLONG_MAX It returns the maximum value of an unsigned long long int object. 18446744073709551615

* The actual value depends on the compiler architecture or library implementation.

Reference: C++ <climits> (limits.h)

C++ program to print the size of integral types

// C++ program to print the size of integral types
#include<iostream>
#include<climits>
using namespace std;

int main()
{
	cout << "CHAR_BIT 		" << CHAR_BIT 	<< endl;
	cout << "SCHAR_MIN 		" << SCHAR_MIN 	<< endl;
	cout << "SCHAR_MAX 		" << SCHAR_MAX 	<< endl;
	cout << "UCHAR_MAX 		" << UCHAR_MAX 	<< endl;
	cout << "CHAR_MIN 		" << CHAR_MIN 	<< endl;
	cout << "CHAR_MAX 		" << CHAR_MAX 	<< endl;
	cout << "MB_LEN_MAX 		" << MB_LEN_MAX << endl;
	cout << "SHRT_MIN 		" << SHRT_MIN 	<< endl;
	cout << "SHRT_MAX 		" << SHRT_MAX 	<< endl;
	cout << "USHRT_MAX 		" << USHRT_MAX 	<< endl;
	cout << "INT_MIN 		" << INT_MIN 	<< endl;
	cout << "INT_MAX 		" << INT_MAX 	<< endl;
	cout << "UINT_MAX 		" << UINT_MAX	<< endl;
	cout << "LONG_MIN 		" << LONG_MIN	<< endl;
	cout << "LONG_MAX 		" << LONG_MAX	<< endl;
	cout << "ULONG_MAX 		" << ULONG_MAX	<< endl;
	cout << "LLONG_MIN 		" << LLONG_MIN	<< endl;
	cout << "LLONG_MAX 		" << LLONG_MAX	<< endl;
	cout << "ULLONG_MAX 		" << ULLONG_MAX	<< endl;

	return 0;
}

Output

CHAR_BIT                8
SCHAR_MIN               -128
SCHAR_MAX               127
UCHAR_MAX               255
CHAR_MIN                -128
CHAR_MAX                127
MB_LEN_MAX              16
SHRT_MIN                -32768
SHRT_MAX                32767
USHRT_MAX               65535
INT_MIN                 -2147483648
INT_MAX                 2147483647
UINT_MAX                4294967295
LONG_MIN                -9223372036854775808
LONG_MAX                9223372036854775807
ULONG_MAX               18446744073709551615
LLONG_MIN               -9223372036854775808
LLONG_MAX               9223372036854775807
ULLONG_MAX              18446744073709551615






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.