Home > Back-end > Consult function is introduced to float type, why the return value is wrong?
Consult function is introduced to float type, why the return value is wrong?
Time:01-16
The following procedure, defines a function f (a) Not declare parameters of a data type, namely K& R "C programming language" has no function prototype in say?
#include #include
Double f (a) { Return a * 1; }
Int main () { Printf (" the result is=% f \ n ", f (10.8 f)); return 0; }
Then compile executable, found that the result is wrong, The result is =1610612736.000000According to the K& R "C programming language" Chinese version of the notes on page 36, 10.8 f should be automatically converted into a double, then return of Why the result is 1610612736.000000. Instead of 10.8?
CodePudding user response:
make cCc Arthur c. - o c Arthur c. : In the function "f" : Arthur c. : 4:8: warning: the type of 'a' defaults to 'int' [- Wimplicit - int] Double f (a)
This is a compilation process and results; Make according to the C language grammar compiler, g + + does not support this kind of method of the building Lord, compile the results, can be determined as int parameter a,
The result is
result is=1.000000
See the building recently in entangled with the noun "function prototype", read a book, is not recommended programming or should pay attention to practice, some nouns, define don't understand, can you fly first, at the back of the study and practice will slowly solve your questions before, in addition, the practice also wants to guide theory, combining both to learn
CodePudding user response:
Strong sense of direction applaud for you,
Modern when we read a classic also should dialectically, also should critically inherit,
Read K& R is more of a feeling of artistic breath, BTW, the translation process is very difficult to guarantee this, suggest that the original text, Rather than as a teaching material,
CodePudding user response:
A little think, ape s and compiler from a proper perspective, is in a state of confrontation, K& R in those days that is described in the suggested that the compiler should how to fit the lazy monkey s, it s message is not addressed to ape, also shouldn't excuse apes s lazy,
You are determined to learn C language, don't you admit that he is lazy, just too lazy to write a type name? A qualified C apes, never consider that a little lazy,