What is the size of int and long type?

Asked 2 years ago, Updated 2 years ago, 25 views

I'd like to know the type and size of C++.

I know it depends on the compiler or architecture (16, 32, 64 bit) Is there a standard in C++?

When I turned to Visual Studio 2008 on a 32-bit architecture, it came out like this.

c++

2022-09-22 15:56

1 Answers

In the C++ standard, there is no fixed maximum range of data types

However, since the minimum range that the data type should be able to represent is fixed, how many bits each data type should be at least,

CHAR_BIT (indicates how many bits a byte is made up of) tells you how many bytes each data type should be at least

Oh, and the char data type is always 1 byte or CHAR_BIT bit.

The size of the data type in C/C++ can be any value that satisfies the following:

Use <limits.h> in C or <limits>, std::numerical_limits in C++ to determine the scope of the data type

Let me give you an example of obtaining an integer range.

//C:
#include <limits.h>
const int min_int = INT_MIN;
const int max_int = INT_MAX;
//C++:
#include <limits>
const int min_int = std::numeric_limits<int>::min();
const int max_int = std::numeric_limits<int>::max();


2022-09-22 15:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.