当前位置:网站首页>C language - Growth Diary -03- function definition and function prototype declaration
C language - Growth Diary -03- function definition and function prototype declaration
2022-06-11 07:42:00 【Zhangxueheng】

The code written like this can run normally , But if we try to remove the function declaration , What's going to happen ?

The compiler will say sum No statement , But I have stated below sum Function is written about sum The code! , Why is that ?
The reason is that the standard is different ,c The language needs to write the function in front of the main function , But doing so will affect the aesthetics of the code , So there is the function prototype declaration , Or function declarations .
such as :

We put void sum The first line of this function is copied , Paste , Put it in main Function with a semicolon “;" In this way, we find that the code is working properly

Simple understanding can be understood as , The functions of the functions to be used ( Not all attributes ) mention main Before the function , Equivalent to giving in advance main Function to say hello , EH , you main The function to be used in the function , I made a statement before you , Tell you in advance main Function , You can't say that the identifier used in your function body is not declared .
The function prototype : Put the function of “ head ” Take it out and add a semicolon , It forms the function prototype . The purpose of the function prototype is to tell the compiler what this function looks like , Include the name of the function 、 Parameters 、 Return type . The actual function header is main Below the function .
When the main function under the function prototype performs operations, it will also judge whether the values in the main function are consistent with those given in the function header .
The prototype of a function does not need to write the name of the parameter , namely , It is also possible to write only data types . Because what the function declaration tells the main function is that there are n A variable , this n What data types are the variables ( The data type is determined according to the problem itself ). The parameter name after the data type in the function declaration can be whether or not , But I still keep it when I write code everyday , And the following function “ head ” equally , This is because it makes sense for human readers , I can understand what it means .
边栏推荐
- Bidirectional linked list simple template (pointer version)
- .NET C#基础(6):命名空间 - 有名字的作用域
- Qunhui ds918 creates m.2 SSD read / write cache
- 2022 low voltage electrician operation certificate test question simulation test platform operation
- C+tinycthread implementation thread
- [atcoder2305] declining (game)
- 运筹学导论
- [cluster] lvs+keepalived high availability cluster
- [atcoder1998] stamp Rally
- Compound RateModel合约解析
猜你喜欢
![[IOT] project management: how to build a better cross functional team?](/img/df/28dbf0f7ba75d1bb3469cc15e70538.png)
[IOT] project management: how to build a better cross functional team?

零基础自学SQL课程 | OUTER JOIN外连接
![[Oracle database] mammy tutorial day04 Sorting Query](/img/79/9db26aa2d9dbb5514427edf03004f4.png)
[Oracle database] mammy tutorial day04 Sorting Query

C language Yanghui triangle code

Miscellany C language

C memory alignment

C wechat upload form data

Seata的几种事务模式

C language to write a calculator calculation logic

Flask页面的分页
随机推荐
20200803 T3 my friends [divide and conquer NTT optimization recursion]
Second remaining learning notes
【AtCoder1984】Wide Swap (拓扑排序转化)
Arduino_ STM development record
Several transaction modes of Seata
C+tinycthread implementation thread
【Oracle 数据库】奶妈式教程day03 排序查询
【AtCoder1981】Shorten Diameter(图论思维)
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
[atcoder2000] leftmost ball (dp+ combination number)
How to prepare for the new PMP syllabus exam?
【AtCoder2307】Tree Game(博弈)
Qunhui ds918 creates m.2 SSD read / write cache
【AtCoder2376】Black and White Tree(博弈)
【AtCoder2304】Cleaning
[atcoder2305] declining (game)
排序——归并排序
Configuration software -- control drag and drop
[atcoder1998] stamp Rally
Djikstra solves the shortest circuit with negative weight