当前位置:网站首页>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
边栏推荐
- JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
- Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
- Codeignier framework implements restful API interface programming
- BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
- Theoretical knowledge of digital image (I) (personal analysis)
- 2022年全国最新消防设施操作员(中级消防设施操作员)题库及答案
- leetcode day4 部门工资最高的员工
- English Translation Spanish - batch English Translation Spanish tools free of charge
- Labelme(一)
- 克服“看牙恐惧”,我们用技术改变行业
猜你喜欢

English translation Arabic - batch English translation Arabic tools free of charge

Basic usage of docker

Integration and implementation of login click graphic verification code in personal blog system

河北邯郸:拓展基层就业空间 助力高校毕业生就业

云计算笔记part.1——系统管理

Oracle insert数据时字符串中有‘单引号问题

Idea properties file display \u solution of not displaying Chinese

【微信小程序开发】页面导航与传参

Design of air combat game based on qtgui image interface

Android-第十三节03xUtils-数据库框架(增删改查)详解
随机推荐
党员故事|李青艾用漫画带动农民增收致富
Netcoreapi operation excel table
How does app automated testing achieve H5 testing
MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
Deploy ZABBIX automatically with saltstack
Read how to deploy highly available k3s with external database
毕马威中国:证券基金经营机构信息技术审计项目发现洞察
基于C语言的信息管理系统和小游戏
11、 学习MySQL UNION 操作符
leetcode day3 超过经理收入的员工
你知道雨的类型有几种?
Taking the opportunity of digital transformation, how can 3C enterprises achieve efficient collaboration through SRM supplier cloud collaboration platform?
There is a 'single quotation mark' problem in the string when Oracle inserts data
时间转日期的sql语句应该怎么写?
[network] cross area network communication learning classification and calculation of IPv4 address
Know small and medium LAN WLAN
OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
China's first chip stamp released: built-in 120um ultra-thin NFC chip
Salt SSH of saltstack