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,

CodePudding user response:

reference forever74 reply: 3/f
a little think, ape s and compiler in 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,

Is not lazy, want to understand why,

CodePudding user response:

The thinking of you still have a question,

I mean if, for example,
With the parent handbook, it read: can frighten children said he did not obey is breaking his leg, but you can't really break his legs,
By children see this sentence, as a normal child, don't go to test, deliberately not obedient will be father interrupt legs?

I mean, I learn to write the correct code, it is not necessary to to study each kind of wrong why spelled wrong, what is wrong,
On the one hand, there are a lot of algorithm or the sky, waiting for me to conquer;
As the learning step by step forward on the other hand, there are some things waiting for you to grow up naturally understand,

CodePudding user response:

Double f ( double a)

CodePudding user response:

refer to 6th floor 4 teacher zhao response:
double f ( double a)

Thank you miss zhao, I want to ask, where is my write wrong? Compile and not an error,

CodePudding user response:

refer to 7th floor oracleperl response:
Quote: refer to the sixth floor 4 teacher zhao response:
double f ( double a)

Thank you miss zhao, I want to ask, where is my write wrong? Compile and no error,

Compile not error because to be compatible with the old syntax rules, parameters not declared type, default int

CodePudding user response:

Application of the building Lord, in the g + +, under the GCC compiler cannot pass, a no type.

CodePudding user response:

refer to the eighth floor 4 teacher zhao response:
Quote: refer to 7th floor oracleperl response:
Quote: refer to the sixth floor 4 teacher zhao response:
double f ( double a)

Thank you miss zhao, I want to ask, where is my write wrong? Compile and no error,

Compile not error because to be compatible with the old syntax rules, parameters don't declare the type, the default int

Thank you miss zhao, about type parameter is not specified, the default is int, I looked at a few books, K& R C programming language "" English version" C and a pointer, "Tan Haoqiang teachers" C programming "
Didn't do that, maybe I didn't see, whether to have "official document" or the relevant information on the basic books

In addition, if a function did not specify a return type, then the default return type is int, this K& R "C programming language" is specified in the

Thank you miss zhao
  • Related