What is the difference between %g and %f in C?

前端 未结 4 791
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 10:05

I was going through The C programming Language by K&R. Here in a statement to print a double variable it is written

printf(\"\\t%g\\n\", sum += atof(lin         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 10:49

    %f and %g does the same thing. Only difference is that %g is the shorter form of %f. That is the precision after decimal point is larger in %f compared to %g

提交回复
热议问题