Re: The printf format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14 January 2013 11:29, GHui wrote:
>
> I code the following code.
> --------------------------
> #include <stdio.h>
> int main(int argc,char **argv)
> {
>     float f[2]={4.0, 37.4};
>     printf("%.2f    %.2f\n",f[0],f[1]);
>     printf("%d    %.2f\n",f[0],f[1]);
> }
>
> And it output is following.
> -------------------------
> 4.00    37.40
> -1    4.00
>
> I confuse that f[1] is 4.00 at the second line.

The code has undefined behaviour. Don't try to reason about undefined
behaviour, you should be glad your computer didn't explode.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux