当前位置:网站首页>C language review 7

C language review 7

2022-06-09 07:54:00 Sakuragi

C Language Check 7

C Language learning , Here is a video of Weng Kai from Zhejiang University , Muke website :https://www.icourse163.org/learn/ZJU-9001?tid=9001#/learn/content. The author's review notes are also mainly based on the video . The main contents of this paper are as follows

  • Programming and design C Language
  • Calculation
  • Judge
  • loop
  • Cycle control
  • data type
  • function
    Definition and use of functions ; The parameters and variables of the function
  • Array
  • The pointer
  • character string
  • Structure type
  • Programming
  • file
  • Linked list

refer
1.


7.1 Definition and use of functions

One 、 Definition

Function is a piece of code , Receive zero or more parameters , Do one thing , Returns zero or one value .
Function definition has Return type 、 Function name 、 Parameter table 、 The body of the function . The form of the function is shown in the following figure :

 Insert picture description here
Even if it is void, Finally, you'd better add return;

Two 、 Function call

When calling a function, you need to use Function name 、 Parameter table , The parameter table is used to call the function . Common calling methods are as follows :
 Insert picture description here

3、 ... and 、 Function return value

The return value of the function is return Keyword implementation , He can return a number , You can also return an expression , A function can have more than one return, But in order to comply with the single export principle , It's better to have only one return.

return Is that , Can be assigned to variable , Can transfer values, etc .

7.2 The parameters and variables of the function

One 、 The function prototype

C When the compiler analyzes code from top to bottom , If in main Other function calls that occur in the function ,C The compiler will look for the definition of the function in the above to match the parameter types .
To make function calls more beautiful , We use function prototypes .
Function prototypes are usually written in function definitions and main Before the function , from Return type 、 Function name 、 The parameter table consists of , That is, the header of the function definition , Form the following :
 Insert picture description here

Two 、 Function parameter

When a function is called, it always passes value .
Each function has its own variable space ( Local space / The local variable ), We call it The local variable , The opposite is Global variables , Parameters are also in this independent local variable , It has nothing to do with other functions .

3、 ... and 、 The local variable
The function produces one local variable per run .
Life span : When variables are created and die .
Scope : The range that variables can access .
For local variables , Both his lifetime and scope are in curly brackets —— block .

It should be noted that , The default initial value of the global variable is 0, Local variables have no default initial value , Some details of local variables are shown below :
 Insert picture description here

原网站

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