What's going on here:
printf("result = %d\n", 1); printf("result = %f\n", 1);
outputs:
result = 1 result = 0.000000
If, before trying to print them, I guarantee the type of these variables, it works fine. Why doesn't the second print statement get implicitly converted to 1.00000?
In the second case, you have a mismatch between your format string and the type of the argument - therefore the result is undefined behavio (u) r.
, 1 1.0, , printf "" C , () (const char *). " " , "" - , printf , .
printf
const char *
, , , printf (, , , ). , vararg, (, ).
, "variable", .
undefined. Int float
: printf ++. Printf - C, , , .
If you need any kind of validation of the actual type, you should use streams and strings - real C ++ alternatives for the old old C-style font.
Interesting, apparently, fine if your put is '1.0'
I assume that printf gets the address of the variable, it does not know what it is. But I would have thought that the compiler would have decency to warn you.
Source: https://habr.com/ru/post/1775281/More articles:The total number of rows in SQL - sqlthis List ListName as parameter? - listLatex: a problem with Multirow - latexThe SharePoint workflow is being used but not displayed. - workflowMerge Subversion: immutable file displayed as modified - svnAndroid: LinearView with fixed widget sizes left and right and flexible in the middle - androidImplementing a parallel queue with two locks - javaHadoop: how to learn how to reduce partition_Id in a step using the Context object - mapreduceHow to start 10 threads at a time from 100 threads in Java? - javaHighly competitive cache access - cachingAll Articles