当前位置:网站首页>Function definition and function parameters

Function definition and function parameters

2022-06-23 18:58:00 Bingling it

Definition of function :

 

  This code's public Is the function header ,void Is the return type ,sum Is the function name , In parentheses is the parameter table ,

The next one for Loop is a function body , This is the introduction of the function

Define the location of the function :

  This is the code that defines the function

 

 

 

The parameters of the function : How to write when calling a function : Call function :

1. If the function has parameters , When you call a function, you must pass it the number 、 Values of the correct type

2. The value that can be passed to the function is the result of the expression , This includes :

 

 

1. Literal

2. Variable

3. The return value of the function

4. The result of the calculation

 

If type of the function being called does not match

1. When the expected parameter type of the function is wider than the given value type of the calling function , The compiler can quietly convert types for you

2.char ——>int——>double

3. When the expected parameter type of the function is narrower than the value type given when calling the function , Need you to write cast

4.(int)5.0

5. When there is no conversion between the expected parameter type of the function and the type of the value given when the function is called ——> no way !

 

 

原网站

版权声明
本文为[Bingling it]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231759525498.html