当前位置:网站首页>C language functions and pointers
C language functions and pointers
2022-07-28 20:00:00 【Embedded Xiaobai aspires to be a boss】
function
An independent function module
2、 Why use functions
2.1 Make the program modular
2.2 Improve code reuse rate
3、 Classification of functions
3.1 Library function
3.1.1、 Import header file
#include <stdio.h> #include <string.h>
3.1.2、 Call function
printf();
Be careful : How many parameters are there , What is the data type , Return value
Function name ( List of actual parameters );
3.2 Custom function
3.2.1 Function definition
Storage type data type Function name ( List of formal parameters )
{
The body of the function ;
Return value ;
}
Storage type :auto、register、extern、static
data type : The return value of the function ( The return value of the function is not written, and the default is int)
Function name : See the name and know the meaning
List of formal parameters : Parameters needed to realize the function , Need to call the incoming
The body of the function : Implementation of specific functions
Return value : If there is no return value , This sentence can be omitted , If there is a return value , There is only one return value
3.2.2 Function call
Function name ( List of actual parameters )
Be careful :
- You need to pass the value of the argument to the formal parameter , The number and data type of arguments must be consistent with formal parameters
- Arguments can be variables 、 Constant 、 It can also be an expression , It must be a definite number
- Arguments and formal parameters are two independent spaces
- Parameter passing is actually copying the value of the argument to the formal parameter
- Parameter is a local variable , Defined when a function is called , Free space at the end of the function call
a、 Invocation time
b、 Call end
c、 Function declaration
If not in main Function , It needs to be in main Function is declared before
Statement : Is to copy the function header directly and add a semicolon
Before making a statement :
Add the statement :
The role of declaration : Help compiler do syntax check
4、 The pointer
1、 Concept
A pointer is a data type , Is a data type that saves addresses
int : It's a data type , Is a data type that holds integers 3 4 5
float: It's a data type , Is a data type that holds floating-point numbers 1.23 3.24
char: It's a data type , Is a data type that stores characters ‘a’ , ‘b’
2、 What is an address
The minimum unit of memory allocation is bytes , Each byte has a number , This number is called address
The essence of address : Number of memory unit
The pointer : The pointer is the address
The nature of the pointer : Number of memory unit
3、 Pointer to the variable
int a;// Integer variables
float b;// Floating point variables
Pointer to the variable : Dedicated to storing addresses ( Number of memory unit ) The variable of
4、 Definition of pointer
Storage type data type * Pointer variable name ;
int *p;
Storage type :auto 、register、static、extern
data type : The data type pointed to by the pointer ( Get rid of * And variable names are the data types pointed to by the pointer ) //int
The data type of the pointer : data type * //int *
& and * They are inverses of each other
5、 Assignment of pointer
Be careful :(1) The direction of the pointer can be changed
(2) When assigning a value to a pointer , Pay attention to type matching
reflection ?
- What is the pointer
- What's the address
- What are pointer variables
- How to define pointer variables
- How to assign values to pointer variables
- What can I do after pointer variable assignment
Be careful : stay 32OS All the pointers in 4 Bytes
stay 64OS All the pointers in 8 Bytes
6、 Null pointer
No pointer to ( The value is 0 The pointer to , It is considered that the pointer does not point to )
Be careful :0 No. address prohibits operation
To operate, you need to change the direction
7、 Wild pointer
I don't know where the pointer points
When local variables are not initialized , The value is a random value
Local pointer variables are wild pointers if they are not initialized
How to avoid the appearance of wild pointer ? Initialize to NULL
int *p = NULL;
8、 Value passed
Realize the exchange of two numbers in the form of sub functions
9、 Address delivery
边栏推荐
- Android-第十三节03xUtils-数据库框架(增删改查)详解
- “中国网事·感动2022”二季度网络感动人物评选结果揭晓
- MATLAB实现的图像分割之边缘检测和连接
- Design of air combat game based on qtgui image interface
- Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
- Cloud computing notes part.1 - system management
- Special draft of Mir | common sense knowledge and reasoning: representation, acquisition and application (deadline on October 31)
- Cloud computing notes part.2 - Application Management
- Leetcode Day1 score ranking
- MIR专题征稿 | 常识知识与推理:表示、获取与应用 (10月31日截稿)
猜你喜欢

并发程序设计,你真的懂吗?

Question bank and answers of the latest national fire-fighting facility operators (intermediate fire-fighting facility operators) in 2022

云计算笔记part.2——应用管理

Basic concept and essence of Architecture

Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)

11. Learn MySQL union operator

KPMG China: insights into information technology audit projects of securities fund management institutions

Sprint for golden nine and silver ten, stay up at night for half a month, collect 1600 real interview questions from Android post of major manufacturers
![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)
[NPP installation plug-in]

中国能否在元宇宙的未来发展中取得突破,占领高地?
随机推荐
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
Leetcode day4 the highest paid employee in the Department
开盘暴涨215%!国产信号链芯片企业芯海科技登陆科创板
基于MATLAB的函数拟合
你知道雨的类型有几种?
MySQL8 Encrypting InnoDB Tablespaces
Why is there no log output in the telnet login interface?
Leetcode Day1 score ranking
Can China make a breakthrough in the future development of the meta universe and occupy the highland?
Design of air combat game based on qtgui image interface
Implementation of markdown editor in editor.md
Redis笔记
Leetcode Day5 delete duplicate email
基于C语言的信息管理系统和小游戏
There is a 'single quotation mark' problem in the string when Oracle inserts data
Servlet learning notes
Crawl IP
Germany and Portugal have announced that they will not disable Huawei 5g equipment, but Germany will set strict restrictions!
2022年下半年系统集成项目管理工程师认证8月20日开班