Jun 2, 2011 at 1:14pm Jun 2, 2011 at 1:14pm UTC
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 Jun 2, 2011 at 1:18pm Jun 2, 2011 at 1:18pm UTC
Jun 2, 2011 at 1:56pm Jun 2, 2011 at 1:56pm UTC
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 Jun 2, 2011 at 1:58pm Jun 2, 2011 at 1:58pm UTC
Jun 3, 2011 at 3:56am Jun 3, 2011 at 3:56am UTC
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
Jun 3, 2011 at 12:28pm Jun 3, 2011 at 12:28pm UTC
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 Jun 3, 2011 at 12:29pm Jun 3, 2011 at 12:29pm UTC