educative.io

Educative

Confused with size allocated for long double

long is used to increase the length of a data type to 4 more bytes
For long double in the table, it shows allocated size in bytes is 16 bytes and values range is +/- 1.7e +/- 308 (~15 digits) which is equivalent to the values range for double.

Doesn’t seem to tally with the description of what long does for an increase in bytes and the value range seems incorrect as well, shouldn’t value range and/or number of digits precision increase?

Did a quick search and based on Microsoft docs Built-in types (C++) | Microsoft Docs it seems like long double is only allocated 8 bytes. Is that accurate?

Confused with how I should understand the usage of long with data types here, would appreciate help with understanding, thank you!


Type your question above this line.

Lesson: https://www.educative.io/collection/page/10370001/6619096843026432/4741386902437888

Hi May_Quek,

The size for long double varies to 8, 12, and 16 bytes. Because it depends on the C++ version, compiler, address busses and etc.
You can check the size of any datatype with sizeof() function. I also checked the size of long double with this function. So I got 16 bytes.