Excerpt from the C99 standard, normative annex F (The C++-standard does not explicitly mention this annex, though it includes all affected functions without change per reference. Also, the types have to match for compatibility.):

IEC 60559 floating-point arithmetic

F.1 Introduction

1 This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for microprocessor systems, second edition (IEC 60559:1989), previously designated IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to remove dependencies on radix and word length. IEC 60559 generally refers to the floating-point standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.356) Where a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since negative and positive infinity are representable in IEC 60559 formats, all real numbers lie within the range of representable values.

So, include <math.h> (or in C++ maybe <cmath>), and test for __STDC_IEC_559__.

If the macro is defined, not only are the types better specified (float being 32bits and double being 64bits among others), but also the behavior of builtin operators and standard-functions is more specified.
Lack of the macro does not give any guarantees.

For x86 and x86_64 (amd64), you can rely on the types float and double being IEC-60559-conformant, though functions using them and operations on them might not be.

Answer from Deduplicator on Stack Overflow
Top answer
1 of 7
22

Excerpt from the C99 standard, normative annex F (The C++-standard does not explicitly mention this annex, though it includes all affected functions without change per reference. Also, the types have to match for compatibility.):

IEC 60559 floating-point arithmetic

F.1 Introduction

1 This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for microprocessor systems, second edition (IEC 60559:1989), previously designated IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to remove dependencies on radix and word length. IEC 60559 generally refers to the floating-point standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.356) Where a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since negative and positive infinity are representable in IEC 60559 formats, all real numbers lie within the range of representable values.

So, include <math.h> (or in C++ maybe <cmath>), and test for __STDC_IEC_559__.

If the macro is defined, not only are the types better specified (float being 32bits and double being 64bits among others), but also the behavior of builtin operators and standard-functions is more specified.
Lack of the macro does not give any guarantees.

For x86 and x86_64 (amd64), you can rely on the types float and double being IEC-60559-conformant, though functions using them and operations on them might not be.

2 of 7
14

Does not say anything about the size.

3.9.1.8

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double. The value representation of floating-point types is implementation-defined. Integral and floating types are collectively called arithmetic types. Specializations of the standard template std::numeric_limits (18.3) shall specify the maximum and minimum values of each arithmetic type for an implementation.

🌐
W3Schools
w3schools.com › c › c_data_types.php
C Data Types
// Create variables int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number char myLetter = 'D'; // Character // Print variables printf("%d\n", myNum); printf("%f\n", myFloatNum); printf("%c\n", myLetter); Try it Yourself » · The data type specifies the size and type of information the variable will store.
Discussions

c - Size of a float variable and compilation - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I'm struggling to understand the behavior of gcc in this. The size of a float ... More on stackoverflow.com
🌐 stackoverflow.com
How does a float support bigger numbers than int?
Floating point numbers are like the computer equivalent of scientific notation. The mass of the earth is 5.972e+27 grams. "5.972e+27" only takes up 9 characters, while 5972000000000000000000000000 takes up 28 characters. If you want to learn how it really works, here's a good concise intro: https://floating-point-gui.de/formats/fp/ More on reddit.com
🌐 r/learnprogramming
9
6
March 4, 2022
How is the sizeof(float) 4 bytes?
Get access to thousands of hours ... alumni in the community today. Start your free trial ... Posted July 9, 2014 1:19am by Vlatko . ... I see why the array length is 3. Just by looking at it, it has 3 values, so the length is 3, correct? What I'm stumped on is why and how the float size is 4 ... More on teamtreehouse.com
🌐 teamtreehouse.com
4
July 9, 2014
What are the differences between float, int, char, and double in C?

The basic types in C are just there to standardize a single unit of memory (a block of bits) that can be used to store a value. We all know that a computer uses bits as its basic unit of information, however a bit is too small to be useful in and of itself, by defining different types we define different blocks of bits and how to interpret them. When we say "int a", the compiler knows that we are dealing with a basic, signed binary number, and knows the amount of memory it needs to set aside to store that number.

The biggest issue is that the exact size definitions are system dependent and not defined in the specifications.

  1. A float and double are both implementations of floating point values in C. floating point numbers are a way to implement decimal and fractional values, of any magnitude in binary and also streamline their arithmetic. It is essentially a binary version of scientific notation. Imagine writing the number 3.14159 In decimal, The mantissa here would be 314159 and the exponent would be -5. You could define a simple function that takes the two numbers (stored in binary) and prints out their combined decimal value, your program could therefore store all decimal numbers as two different numbers in binary, and use its own functions to add them together, print them etc. However, C streamlines this process by giving you a simple container that does all that work for you behind the scene. A floating point standard describes how you would encode the mantissa and exponent into a single binary number. In C, the only difference between a float and a double is the amount of memory set aside to store your number, and thus the greater range and precision of the numbers that you can store. The benefit of this is that you can also describe large integer numbers, for instance, you would need 32 bits to write the number "4 billion" explicitly in binary, but you only need 8 to do the same in floating point (4 x 109). However, you would not be able to write the number 4,123,456,789 as an 8 bit floating point or even a 32 bit floating point number (as you still need to encode the exponent), but it will fit perfectly well in a 32 bit int.

  2. A char and int are just basic binary numbers, their only difference being in length (potentially). A character is defined as the smallest unit of data necessary to hold a single text character for that architecture, this is a bit abstractly defined, but for most computer today running x86 platforms, a char is defined as 8 bits (although, on unicode systems it could be 16 bits). An integer is another basic binary number, but it is required to be at least 16 bits long (typically it is either 32 or 64 on modern systems). So a 8 bit char is capable of encoding 256 unique characters, or a number between 0-255 (or a number between -127 and 128) the difference is only in how you interpret the collection of bits. An 32 bit int can store a number between 0 and slightly over 4 billion, or you could half that range and use it to represent a number between (roughly) -2 billion and 2 billion

On some systems, the size of an int may be the same as the size of float, from the memory point of view they are just collections of bits, however the processor will interpret the values differently, and will actually use different circuits to add two numbers together if they are floats vs if they ints.

More on reddit.com
🌐 r/learnprogramming
9
11
October 9, 2013

Excerpt from the C99 standard, normative annex F (The C++-standard does not explicitly mention this annex, though it includes all affected functions without change per reference. Also, the types have to match for compatibility.):

IEC 60559 floating-point arithmetic

F.1 Introduction

1 This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for microprocessor systems, second edition (IEC 60559:1989), previously designated IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to remove dependencies on radix and word length. IEC 60559 generally refers to the floating-point standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.356) Where a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified behavior is adopted by reference, unless stated otherwise. Since negative and positive infinity are representable in IEC 60559 formats, all real numbers lie within the range of representable values.

So, include <math.h> (or in C++ maybe <cmath>), and test for __STDC_IEC_559__.

If the macro is defined, not only are the types better specified (float being 32bits and double being 64bits among others), but also the behavior of builtin operators and standard-functions is more specified.
Lack of the macro does not give any guarantees.

For x86 and x86_64 (amd64), you can rely on the types float and double being IEC-60559-conformant, though functions using them and operations on them might not be.

Answer from Deduplicator on Stack Overflow
🌐
Wikipedia
en.wikipedia.org › wiki › C_data_types
C data types - Wikipedia
4 days ago - Information about the actual properties, such as size, of the basic arithmetic types, is provided via macro constants in two headers: <limits.h> header defines macros for integer types and <float.h> header defines macros for floating-point types.
🌐
Programiz
programiz.com › c-programming › examples › sizeof-operator-example
C Program to Find the Size of int, float, double and char
The sizeof(variable) operator computes the size of a variable. And, to print the result returned by sizeof, we use either %lu or %zu format specifier. #include<stdio.h> int main() { int intType; float floatType; double doubleType; char charType; // sizeof evaluates the size of a variable printf("Size of int: %zu bytes\n", sizeof(intType)); printf("Size of float: %zu bytes\n", sizeof(floatType)); printf("Size of double: %zu bytes\n", sizeof(doubleType)); printf("Size of char: %zu byte\n", sizeof(charType)); return 0; }
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_data_types.htm
C - Data Types
When you compile and execute the above program, it produces the following result on Linux − · Storage size for float : 4 FLT_MAX : 3.40282e+38 FLT_MIN : 1.17549e-38 -FLT_MAX : -3.40282e+38 -FLT_MIN : -1.17549e-38 DBL_MAX : 1.79769e+308 DBL_MIN ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-float-and-double
C Float and Double - GeeksforGeeks
July 23, 2025 - In this article, we will study ... decimal values with precision up to 6-7 decimal places. ... The size of the float is 4 bytes....
🌐
Programiz
programiz.com › c-programming › c-data-types
C Data Types
The size of float (single precision float data type) is 4 bytes. And the size of double (double precision float data type) is 8 bytes. Keyword char is used for declaring character type variables. For example, ... The size of the character variable is 1 byte. void is an incomplete type.
🌐
Medium
medium.com › @Dev_Frank › datatypes-in-c-int-char-float-def790690c42
DATATYPES IN C (int, char, float) | by Dev Frank | Medium
February 5, 2024 - Floating-point numbers are numbers that have a decimal point or are expressed in exponential (scientific) notation. Here are the key characteristics and considerations regarding the float data type: The size of a float variable is typically 4 bytes ...
Top answer
1 of 5
2

1)

Does sizeof(variable) simply get the variable type and return sizeof(type), which in this case would explain the result ?

Except for variable-length arrays, sizeof doesn't evaluate its operand. So yes, all it cares is the type. So sizeof(someFloatNumb) is 4 which is equivalent to sizeof(float). This explains printf("%i\n", sizeof(someFloatNumb));.

2)

[..] But I can still store a 8 bytes real value in a float, and my compiler says nothing about it. Does/Can gcc grow the capacity of a type ? (managing multiple variables behind the curtains to allow us that sort of things)

No. Capacity doesn't grow. You simply misunderstood how floats are represented/stored. sizeof(float) being 4 doesn't mean it can't store more than 2^32 (assuming 1 byte == 8 bits). See Floating point representation. What the maximum value of a float can represent is defined by the constant FLT_MAX (see <float.h>). sizeof(someFloatNumb) simply yields how many bytes the object (someFloatNumb) takes up in memory which isn't necessarily equal to the range of values it can represent. This explains why printf("%f\n", someFloatNumb); prints the value as expected (and there's no automatic "capacity growth").

3)

printf("%i\n", sizeof(281474976710656));

This is slightly more involved. As said before in (1), sizeof only cares about the type here. But the type of 281474976710656 is not necessarily int. The C standard defines the type of integer constants according to the smallest type that can represent the value. See https://stackoverflow.com/a/42115024/1275169 for an explanation.

On my system 281474976710656 can't be represented in an int and it's stored in a long int which is likely to be case on your system as well. So what you see is essentially equivalent to sizeof(long).

There's no portable way to determine the type of integer constants. But since you are using gcc, you could use a little trick with typeof:

typeof(281474976710656) x;
printf("%s", x); /* deliberately using '%s' to generate warning from gcc. */

generates:

warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘long int’ [-Wformat=] printf("%s", x);


P.S: sizeof results a size_t for which the correct format specifier is %zu. So that's what you should be using in your 1st and 3rd printf statements.

2 of 5
2

This doesn't store "8 bytes" of data, that value gets converted to an integer by the compiler, then converted to a float for assignment:

float someFloatNumb = 0xFFFFFFFFFFFF; // 6 bytes of data

Since float can represent large values, this isn't a big deal, but you will lose a lot of precision if you're only using 32-bit floats. Notice there's a slight but important difference here:

float value = 281474976710656.000000;
int value   = 281474976710655;

This is because float becomes an approximation when it runs out of precision.

Capacities don't "grow" for standard C types. You'll have to use a "bignum" library for that.

🌐
Vultr
docs.vultr.com › clang › examples › find-the-size-of-int-float-double-and-char
C Program to Find the Size of int, float, double and char
September 27, 2024 - This code outputs the size of an int in bytes. The %zu format specifier is used for size_t type returned by sizeof. Initialize a float variable.
🌐
Reddit
reddit.com › r/learnprogramming › how does a float support bigger numbers than int?
r/learnprogramming on Reddit: How does a float support bigger numbers than int?
March 4, 2022 -

Hi!

I've got a question about C, which has popped up in my mind while following CS50's week 2 and looking up for extra info online.

Apparently, float and int take up the same amount of bytes, 4. However, according to this page, has its limit on 2,147,483,647, while float supports numbers as high as 3.4E+38.

I tried the following code on Programiz's compiler:

#include <stdio.h>

int main() {
    // Write C code here
    int i = 2000000000000000;
    printf("Int value: %i \n", i);
    
    float j = 2000000000000000.0;
    printf("Float value: %f", j);
    
    return 0;
}

Which returned:

Int value: 1233977344 
Float value: 1999999973982208.000000

While the integer overflows, as expected, the float returns a relatively precise value (not completely precise, but close to my input).

How is this possible, considering both take up 4 bytes of memory?

Thank you!

EDIT: Thank you all for your answers! :)

Top answer
1 of 6
12
The trick is that an integer just counts up from zero, but a float uses some of its size to say "how big is this number." Let's say we have 10 "digits" to represent a number. For an integer, we'd say "0000000000" means 0, "0000000001" means 1, and "9999999999" means 9,999,999,999. And that's as high as you can go. For a float, we've still got 10 digits, but let's say we use the first 8 to define numbers, and we use the last 2 to say "how far to move the decimal point." So "1234567890" might mean "take the number 1.2345678 and move the decimal 90 spaces to the right, a.k.a 1.2345678 x 10^90". See how the decimal point moves around? That's what they mean by a "floating point." That's pretty much exactly what floating point numbers do in real life, except they use binary instead of base 10. A 32 bit floating point number uses 1 bit to say "positive or negative," then 8 bits to say "how big is the exponent aka how many decimal points are we sliding the number", and then the last 23 bits are the "mantissa," which is the number that we're going to move the decimal point around. The good thing about floats is that they can express really huge or really tiny numbers in a compact amount of space, but the downside is that they have less precision than an integer, and the math gets weird around the edges. You can easily represent "about 1.23 quadrillion" as a float, but you can't represent precisely 1,230,000,000,000,007.
2 of 6
8
Floating point numbers are like the computer equivalent of scientific notation. The mass of the earth is 5.972e+27 grams. "5.972e+27" only takes up 9 characters, while 5972000000000000000000000000 takes up 28 characters. If you want to learn how it really works, here's a good concise intro: https://floating-point-gui.de/formats/fp/
🌐
Quora
quora.com › What-are-the-sizes-of-char-int-float-double-and-bool
What are the sizes of char, int, float, double, and bool? - Quora
The size of char, int and float are 1,2 and 4 respectively. But size may vary from compiler to compiler.
Top answer
1 of 4
5
Hi Vlatko, The size of a float or other data types for that matter is dependent upon the system. It has to do with the hardware architecture and the compiler. This float, 10498.429, would also be 4 bytes in memory. If a given computer system had a float size of 4 bytes then all floats are 4 bytes. You should not be thinking of these floating point numbers as characters in an array and counting how many characters there are. So when you do float numbers[] = {11.11, 22.22, 33.33}; The computer will set aside 12 bytes of memory because it knows each float is 4 bytes and it has to make room for 3 of them. The array could have been float numbers[] = {0.5, 9.3, 32897.4, 98.568}; and the computer will still reserve 12 bytes of memory. So when you do sizeof(numbers) that evaluates to 12 because you're asking for the total size in memory that is occupied by that array. I think one of the main points that you should get from this video is that you don't really need to know the size of a float. You want to do your calculations in a way that is independent of the system it's running on. For instance, the teacher calculated the array length with sizeof (numbers) / sizeof (float) and that comes out to 3 (12 / 4 = 3) Well, you could get that answer by doing this sizeof(numbers) / 4 The problem with this is that we have assumed a float size of 4. If we now run this program on a system where the float size is something else then we're going to get the wrong length. I hope this clears it up for you.
2 of 4
2
Here's a little extra information for the more curious: The way memory works is 0's and 1's. And the way computers count is by using a bunch of 0's and 1's all in a row (binary). The reason it's 0's and 1's has to do with storing electrical charge. If you want any more than two lonely numbers—0 and 1—you have to start setting them next to one another. A byte is 8 of these 0's and 1's set next to one another. Here's an example of a byte: 00101100. A byte has 256 possible combinations (2 to the power of 8). This is part of why you'll see RGB colors valued up to 256. If you have four bytes, you have over 4 billion possible combinations. Computers actually do something cool and tricky with floats in C (or in Objective-C, all the same), but ignoring that, someone back in the history of computing decided it would make sense for a float to be 4 bytes (or 32-bits). All "sizeof" is asking for in C is the number of bytes for that primitive float type. It doesn't matter what number you assign to that float, it's going to be 4 bytes regardless. So now if you have some array of floats, and you ask it what it's "sizeof" is, the C language is only going to understand you as asking what the size of a general float is. It doesn't actually understand that you have an array; it thinks you're just asking about a float. So if you want to keep track of how large your array is (for example, if you ever do anything in OpenGL), you'll need to save an integer that refers to the size of the float array. For instance, it might look like this: ```` C float myarray[] = malloc( sizeof(float) * 300 ); // suppose I have 300 elements in my array. int myarraysize = sizeof(float) * 300; // or you could use sizet instead of int. ````
🌐
Learn C
learnc.net › home › learn c programming › c float
C Float Types
April 13, 2025 - It means that a float gives 1 sign bit, 8 bits of exponent, and 23 bits of significand. The double type is for a number with the double-precision that gives 1 sign bit, 11 bits of exponent, and 52 bits of significand.
🌐
LunaNotes
lunanotes.io › summary › understanding-float-double-and-long-double-data-types-in-c-programming
Understanding Float, Double, and Long Double Data Types in C Programming | Video Summary by LunaNotes
November 21, 2025 - Float: Typically occupies 4 bytes of memory; follows the IEEE754 Single Precision standard. Double: Commonly uses 8 bytes; adheres to the IEEE754 Double Precision format. Long Double: Usually takes up 12 bytes or more; utilizes Extended Precision ...
🌐
BeginnersBook
beginnersbook.com › 2017 › 09 › c-program-to-find-the-size-of-int-float-double-and-char
C Program to find the Size of int, float, double and char
#include<stdio.h> int main() { printf("Size of char: %ld byte\n",sizeof(char)); printf("Size of int: %ld bytes\n",sizeof(int)); printf("Size of float: %ld bytes\n",sizeof(float)); printf("Size of double: %ld bytes", sizeof(double)); return 0; }
🌐
BYJUS
byjus.com › gate › size-of-data-types-in-c
Size of Data Types in C
February 16, 2024 - int – these are integers. They typically reflect the integer’s natural size on a host machine. double – these are double-precision types of floating-point. Apart from this, one can also apply various numbers of qualifiers to the basic data types.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › type-float
Type float | Microsoft Learn
Single-precision values with float type have 4 bytes, consisting of a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0. Since the high-order bit of the mantissa is always ...
🌐
W3Resource
w3resource.com › c-programming › c-data-types.php
C Data Types - w3resource
August 19, 2022 - To extend the precision further, we may use long double which uses 80 bits. The following table shows the size and range of the type-specifiers on most common implementations : The sizes and ranges for each of C's data types in our ...