formatted print

Hi
I have a noob question wishing someone will explain this to me.
in a printf what does 10.5f mean?
could i get some examples?
Im doing assignment and i have example output
"%d %10.5f"
%
123 24.0 // bold as output.
suppose I have stack of numbers
123 <- top of stack
24

the assingment states
% is a formatted print taking a variable number of operands depending on the format string

thanks in advance

Last edited on
closed account (zb0S216C)
A floating-point numerical value with a f suffix denotes a float value. For example:

1
2
float float_value( 10.5f );
double double_value( 10.5 );


The f suffix basically tells the compiler that it's working with a float value.

In printf( )[1], the first argument is the format string. This string holds the format data in which the string is printed.

References:
[1]http://www.cplusplus.com/reference/clibrary/cstdio/printf/


Wazzak
Last edited on
so the number 10.5 is just a value? and any ideas on how this came about?

user inputs
"%d %10.5f"
%
123 24.0 // bold as output.

suppose I have stack of numbers
123 <- top of stack
24
Perhaps you should start by reading the relevant documentation. There's a lot you can do with printf.
http://msdn.microsoft.com/en-us/library/56e442dc%28v=VS.71%29.aspx
http://pubs.opengroup.org/onlinepubs/007908799/xbd/notation.html
closed account (zb0S216C)
whoami32 wrote:
so the number 10.5 is just a value?

Both 10.5f and 10.5 are both numbers. However, double has a greater precision than float. Compared to float, double has a larger size.

Wazzak
Last edited on
Topic archived. No new replies allowed.