C function syntax -


I'm new to C and started to look through Learn C (). In the Function section, if the user requests the exercise to print x bigger if x 10 My point is that the official answer is

  int print_big (int number) {if (number> 10) {printf ("% d big \ n", number); }}  

Why is not a int of the output and there is no zero type? Also, can anybody please explain that the type of output is a integer when the function is printing x large text? Is that because the x bigger is too small to fit in the text memory "container" will fit an integer?

In addition, can anyone please explain how the function is printing? Is there a bigger text when the type of output is an integer?

Output and return values ​​are two completely different things; The caller of the text function is not being reverted, it is being written only on the standard output stream

In writing, the caller of nothing function can not be undone. Used to be. It will be used as:

  zero foo (zero) {int val = 0; Printf ("Enter a number:"); Scans ("% d", and;); Print_big (val); }  

Note that foo does not specify the result of print_big ; This is what it means, "the collar is not using value"

As noted in the comments, the solution codes were prior to the language standard of 1989 (1970s Hold hold can happen from the mid-1980s decade. Until the 1989 standard, there was no zero type; The standard type of practice was to do int and the caller did not use the return value. Although this solution does not excuse the lack of return statement in the code.

Or it may be just a poorly written code (which is more likely); Unfortunately, there are a lot of people who think that they know and want to share their knowledge, but they get many things wrong and cross many wrong information and bad practices. . Be aware of all online tutorials and most printed references

The official solution must be typed in either zero :

  void print_big (int number) {If (x & gt; numbers) printf ("x is big \ n"); }  

or it has a clear return statement:

  int print_big (int number) {if (x> number) printf (" X bigger \ n "); Return 0; }  

This discussion should clearly state that the value returned by a function is not used, for example, printf < The / code> function gives the number of bytes written in the output stream, but you often do not see code that clearly checks that result; The result is usually dismissed (i.e., nothing). Similarly, scanf returns the number of successful conversions and assignments. Again, many people ignore this result (though they should not).


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -