当前位置:网站首页>Functions and parameters
Functions and parameters
2022-07-19 05:30:00 【Learn to put down ta】
function
C Language functions need to be declared before being defined
Statement ( Form good habits , Write a function declaration )
return type Function name ( parameter list );
Don't forget the semicolon at the end of the function declaration .
Definition
return type Function name ( parameter list )
{
The body of the function ;
}
If the return value type is not specified, write void, Do not write the default return integer , No parameters can be left blank , Brackets must be written , There is no semicolon at the end of the function
Use
Write the function name like calling a library function ( Parameters ) Just go
Function name ( Parameters );
Note that the parameters here are the arguments passed in by the user , The above definition is formal parameter
Function parameters and pointers
1、 Pass value
void swap(int x,int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
Functions can be realized in the function body , But do not change the data outside the function . After calling this function x,y The value of , It is equivalent to copying the value of the parameter and exchanging the copied value
2、 Byref
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
In this way, the address of the argument is passed into the function , Function directly operates on the address data , The data outside the function will change
3、 quote
void swap(int &x,int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
The function is the same as that of address , But a reference is equivalent to giving a variable another name , In fact, it still operates on the incoming variables
4、 Pass array
void print(int a[10])
{
int i;
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
}
It's different from passing only one number , There is no such transfer method as copying the entire array , Talked about before , The array name is equivalent to its pointer , Because the array name is the address of the first element , Note the address , So if you pass in an array , It is possible to modify the value of a number in the array in the function .
边栏推荐
猜你喜欢

web3js开发技术

Easypoi之excel模板导出

C语言&位域

Wechat applet learning notes

Beginner's Guide to learning penetration testing

Swagger configuration and use
![[AI] action recognition using simple neural network -- Based on coco key points](/img/67/cd6be6e070fb5d4d44ee043ebd7fac.png)
[AI] action recognition using simple neural network -- Based on coco key points

第一个智能合约程序Faucet.sol

软件测试就业前景怎样 人才需求大,岗位稳定性强

The latest news of spring recruitment in 2022: the average salary of it Internet industry is 18500 yuan
随机推荐
The latest news of spring recruitment in 2022: the average salary of it Internet industry is 18500 yuan
ETL工具——kettle实现简单的数据迁移
Redis source code analysis skip table implementation
User mode protocol stack - UDP implementation based on netmap
ambari2.7.5集成es6.4.2
2022年春招最新消息:IT互联网行业平均薪资18500元
2.6.2 内存泄漏
Excel template export of easypoi
Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr
Face scum counter attack: thread pool lethal serial eighteen questions, the interviewer praised me straight
Easypoi之excel简单导出
Easypoi excel simple export
SQL injection
用Flink SQL流化市场数据2:盘中风险价值
Easypoi之excel多sheet导入
BUUCTF web WarmUp
Implementation of synchronization interface of 6 libcurl based on libco
The first smart contract program faucet sol
特殊指针的一些应用
Cityengine 3D pipe modeling tutorial