The difference between the C language and% f% lf of the specifier

Because it is said printf c language than C ++, the cout much faster (of course I tried it, the output of 10,000 lines, about 1/15 of the gap, not great).
I run in the cpp file not found this program to output the correct result

#include<stdio.h>
const double pi=3.14;
int main()
{
    double r=3;
    double s;
    scanf("%lf",&r);
    s=r*r*pi;
    printf("%f\n",s);
    scanf("%lf",&r);
    s=r*r*pi;
    printf("%lf",s);
    return 0;
}

The first input can be output correctly, the second time will not be output correctly, I checked and found that C language ** scanf () ** in float format corresponding to the icon is% f, the format corresponding to the icon is double % lf; and printf () format characters float and double are% f. So this second output of this code will error.
.C file may try, you will find are two possible outputs.

Published 17 original articles · won praise 16 · views 1155

Guess you like

Origin blog.csdn.net/XYshaonianhaofang/article/details/104119228