0

related to c

Why does this statement. If int a=12,floatb=1.234 printf("%*f",a,b) execute and give 1.2340000

29th Jan 2020, 3:36 PM
Sooraj m
Sooraj m - avatar
4 Antworten
+ 2
The * you've used tells the printf function to use the "a" (12) for the field width. Also..just to add... printf("%*.2f",a,b)....the ".2" (or any number you need) will display 2 decimal places, which can also be specified in a similar method to the field width...e.g printf("%*.*f" ,a, 2 ,b);
29th Jan 2020, 3:51 PM
rodwynnejones
rodwynnejones - avatar
+ 1
"The value is not truncated even if the result is larger." quoted from here;- http://www.cplusplus.com/reference/cstdio/printf/
29th Jan 2020, 4:07 PM
rodwynnejones
rodwynnejones - avatar
0
If suppose I have given a=0 would it still execute
29th Jan 2020, 3:55 PM
Sooraj m
Sooraj m - avatar
0
Thanx
29th Jan 2020, 4:10 PM
Sooraj m
Sooraj m - avatar