You can do it like this:

printf("%.6f", myFloat);

6 represents the number of digits after the decimal separator.

Answer from Roman Byshko on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-float-and-double
C Float and Double - GeeksforGeeks
July 23, 2025 - Float and double are two primitive data types in C programming that are used to store decimal values.
🌐
TechOnTheNet
techonthenet.com › c_language › variables › create_float.php
C Language: Float Variables
This C tutorial explains how to declare and use floating-point (float) variables with syntax and examples.
🌐
Northern Michigan University
nmu.edu › Webb › ArchivedHTML › MathComputerScience › c_programming › c_008.htm
More About Float and Double Variables
MORE ABOUT FLOAT AND DOUBLE VARIABLES C displays both float and double variables to six decimal places.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › c-floating-point-constants
C Floating-Point Constants | Microsoft Learn
January 25, 2023 - Use floating-point constants to represent floating-point values that can't be changed.
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)FloatingPoint.html
C/FloatingPoint
Real numbers are represented in C by the floating point types float, double, and long double. Just as the integer types can't represent all integers because they fit in a bounded number of bytes, so also the floating-point types can't represent all real numbers.
🌐
W3Schools
w3schools.com › c › ref_keyword_float.php
C float Keyword
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... The float keyword is a data type which stores fractional numbers.
🌐
TutorialsPoint
tutorialspoint.com › float-and-double-in-c
Float and Double in C
September 2, 2023 - Float is a datatype which is used to represent the floating point numbers. It is a 32-bit IEEE 754 single precision floating point number (1-bit for the sign, 8-bit for exponent, 23*-bit for the value.
Find elsewhere
🌐
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.
🌐
NxtWave
ccbp.in › blog › articles › float-in-c
Float in C Programming | Definition, Syntax & Examples
C programming float is a data type used to store numbers with decimal points, also known as floating-point numbers. These are useful for representing fractional values in calculations.
🌐
TutorialsPoint
tutorialspoint.com › c_standard_library › float_h.htm
C Library - <float.h>
The maximum value of float = 3.4028234664e+38 The minimum value of float = 1.1754943508e-38 The number of digits in the number = 7.2996655210e-312 · Following is the C Library header file float.h to define the values of few macros(float) constant.
Top answer
1 of 3
4

float is a type name of floating point type. Floatin point numbers are used to represent a subset of rational numbers with finite precision.

Given a type name T, T* is a type name that is a pointer type. Specifically, it is a pointer to the type T. A pointer is used to indirectly "refer" (point) to another object. The value of a pointer is the memory address where the pointed object is stored. It is possible to get the value of the pointed object by indirecting through the pointer.

Pointers are often used as an iterator to traverse through elements of an array. This is made possible by "pointer arithmetic": By adding 1 to a pointer, changes it to point to the successor element of an array.

Thus, float* is a pointer to float. Furthermore float** is a pointer to a float* i.e. a pointer to a pointer to a float. Finally, float*** is a pointer to a float** i.e. a pointer to a pointer to a pointer to a float.

what would be its equivalent in C++?

Pointers exist in C++ as well as pointers to pointers and pointers to pointers to pointers.

I saw some old posts explaining some not usual declaration.

It is quite rare to need a "three-star" pointer in C, and extremely rare to need it in C++, but there is nothing special about it.

2 of 3
0

The other answers answer your question well, and are correct in that this is also valid C++. However, I would be inclined to say that a "more C++11" equivalent of the triple-star would be:

std::vector<std::vector<std::vector<float>>>

Before C++11, this would be a little uglier:

std::vector<std::vector<std::vector<float> > >
🌐
cppreference.com
en.cppreference.com › w › c › keyword › float.html
C keywords: float - cppreference.com
C language · [edit] Keywords · [edit] float type: as the declaration of the type · Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/keyword/float&oldid=44106" Support us · Recent changes · FAQ · Offline version · What links here · Related changes ·
🌐
ThoughtCo
thoughtco.com › definition-of-float-958293
What Is Float in C, C++ and C# Programming?
May 8, 2025 - By definition, float in C, C++ and C# is a variable with floating decimal point. It can contain whole numbers as well as fractions.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › type-float
Type float | Microsoft Learn
You can try changing directories. ... Floating-point numbers use the IEEE (Institute of Electrical and Electronics Engineers) format. 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.
🌐
Wikipedia
en.wikipedia.org › wiki › C_data_types
C data types - Wikipedia
1 week ago - Usually, the 32-bit and 64-bit IEEE 754 binary floating-point formats are used for float and double respectively. The C99 standard includes new real floating-point types float_t and double_t, defined in <math.h>. They correspond to the types used for the intermediate results of floating-point expressions when FLT_EVAL_METHOD is 0, 1, or 2.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Floating_002dPoint-Data-Types.html
Floating-Point Data Types (GNU C Language Manual)
Next: Complex Data Types, Previous: Integer Data Types, Up: Primitive Data Types [Contents][Index] Floating point is the binary analogue of scientific notation: internally it represents a number as a fraction and a binary exponent; the value is that fraction multiplied by the specified power of 2.
🌐
PrepBytes
prepbytes.com › home › c programming › float in c
Float in C - Syntax, Examples and Uses
January 8, 2024 - In the C programming language, float is a data type used to represent single-precision floating-point numbers. Floating-point numbers are used to handle real numbers with decimal points, providing a way to represent a wide range of values, from ...
🌐
W3Schools
w3schools.com › c › c_data_types_numbers.php
C Numeric Data Types
C Examples C Real-Life Examples ... a whole number without decimals, like 35 or 1000, and float or double when you need a floating point number (with decimals), like 9.99 or 3.14515....
Top answer
1 of 2
3

The difference is

  1. You are dereferencing the int and casting it to float in

    printf("(float)* : %f\n", (float)*iptr);
    

    which is fine.

  2. You are casting the int pointer to a float pointer, and printing the float pointer with the "%f" specifier is undefined behavior, the correct specifier for printing pointers is "%p", so

    printf("(float*) : %f\n", (float*)iptr);
    

    is wrong, it should be

    printf("(float*) : %p\n", (void *) iptr);
    

    casting to float * here is not meaningful, because the void * address is the same as the float * address and also the int * address, the difference would be when you do pointer arithmetic.

  3. You are casting the int pointer to a float and dereferencing the resulting float pointer, although it will violate strict aliasing rules in

    printf("(float*) : %f\n", *(float*)iptr);
    

    which is also undefined behavior

2 of 2
3

The first one is correct.

i is an int variable, and iptr a pointer to that int.

  1. (float)*iptr: *iptr dereferences iptr, which returns an int. Then that int is converted to a temporary float containing the same value. And that float is used by printf.

  2. *(float*)iptr: Attempts to cast a pointer-to-int into a pointer-to-float. This is invalid, and should produce a compiler warning or error. It creates a pointer with the same address, but with the type saying that it points to a float value.

    The * operator then dereferences it, so the int is read as if it were a float. So the resulting float would be invalid, and it could result in a segfault because floats are longer than ints, so it reads more memory than there is allocated for the int.

  3. (float*)iptr: Same problem, but it doesn't dereference the (invalid) pointer, and passes a pointer-to-float into printf, instead of a float. But printf expects a float. Some compilers should also produce a warning/error here because the format string indicates what value types are expected.

    If the format specifier indicates %p, it expects a pointer (void*, float*, or any other). It will then print out the address, and not the value it points to. This can be useful in debugging for example.