当前位置:网站首页>C language learning log 11.7

C language learning log 11.7

2022-06-13 04:57:00 Today is also a day without baldness

One . function

(1) Function definition :

(2) Call function :

Function name ( Parameter values );

() It plays an important role in representing function calls , Even if there are no parameters ()

If there are parameters , You need to give the correct quantity and order , These values are used to initialize the parameters in the function in sequence

(3) Returns a value from a function :

return Stop the execution of the function , And return a value .        It can be written. return; It means that the execution of the function is stopped without returning the value .

return expression ; return You can also use multiple .

(4) Functions that do not return values :

Format :void Function name ( Parameter table )        requirement :1. Cannot use with value return

                                                              2. There can be no return

                                                              3. The return value cannot be assigned when calling

(5) The local variable :

Lifetime of variables : When does this variable start to appear , When will it die .

Scope : stay ( Code ) What scope can access this variable ( This variable can work )

For local variables , The answers to these two questions are unified : In braces ,( Braces are also called “ block ”)

Of local variables The rules :1. It is defined within a block —— Can be in a function block ; It can also be in a statement block ; You can even pull a pair of braces to define variables .

                             2. Before the program runs into this block , The variables are nonexistent , Get out of this block , The variables are gone .

                             3. Variables defined outside the block are still valid inside .

                             4. A variable with the same name as the outside is defined in the block, which masks the outside .

                             5. A variable with the same name cannot be defined in the same block .

                             6. Local variables are not initialized by default .

(6) Something special

1. When the function has no arguments : It should be expressed as void f(void); If void f(); It means f The parameter table of the function is unknown , It does not mean that there are no parameters

2. Functions cannot be nested inside .

 

原网站

版权声明
本文为[Today is also a day without baldness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280517426084.html