当前位置:网站首页>Pointer array parameter passing, pointer parameter passing
Pointer array parameter passing, pointer parameter passing
2022-07-02 22:25:00 【It's Yi'an】
Catalog
The pointer passes the parameter
Array parameters
One dimensional array
When we pass in a one-dimensional array, we enter the array name , The array name is a pointer to the first element
When receiving the function , Just make sure that the type of the incoming address is the same
#include<stdio.h>
void test(int arr[]) {} //int arr[] Can be seen as int *arr
void test1(int arr[10]){} // What is passed in is the address pointing to the first element , and [] Independent of the value in
void test2(int* arr){} // One int* Pointer to type
int main(void) {
int arr[10] = { 0 };
test(arr); // take arr As a pointer , Point to first element , The type is int*
test1(arr);
test2(arr);
return 0;
}Two dimensional array
When we pass in a two-dimensional array, we also enter the array name , The array name is an address that points to the first element , But here, the first element is regarded as a one-dimensional array
int arr[3][5] = {
{1,2,3,4,5}, // First element arr It represents the address of the one-dimensional array
{2,3,4,5,6}, // The second element
{3,4,5,6,7} // The third element
};Same will arr As a pointer , Is a pointer to an array , That is, array pointers , The type is int(*)[5].
When receiving the function , Just make sure that the type of the incoming address is the same
#include<stdio.h>
void test(int arr[3][5]) {} //int arr[][5] Can be seen as int(*)[5]
void test1(int arr[][5]) {} // What is passed in is to point to the first element ( Array ) The address of , And the first [] Independent of the value in
void test2(int(*arr)[5]) {}
//*arr=arr[0],*(arr+i)=arr[i]
//*(arr[i]+j)=arr[i][j]
//*(*(arr+i)+j)=arr[i][j]
// About [] The function of array pointer can be seen in the previous article
int main(void) {
int arr[3][5] = {
{1,2,3,4,5}, // First element arr It represents the address of the one-dimensional array
{2,3,4,5,6}, // The second element
{3,4,5,6,7} // The third element
};
test(arr); // take arr As a pointer , Point to first element ( Array ), The type is int(*)[5]
test1(arr);
test2(arr);
return 0;
}The pointer passes the parameter
First level pointer
When the first level pointer is passed into the function, it is passed to the address , That's the pointer , When receiving, as long as the type is the same .
#include<stdio.h>
void test(int* p) {} // Both int* Pointer to type
void test1(int p[]) {}
void test2(char* p) {} // Both char* Pointer to type
void test3(char p[]) {}
int main(void) {
int a = 10;
int* p = &a;
test(p);
test1(&a);
char b = 'w';
char* p1 = &b;
test2(p1);
test3(&b);
return 0;
}The secondary pointer
The function receives a second level pointer , The parameter type is a secondary pointer , As long as it is the address of the element up two levels .
void test(int** p) {} //int** type
int a = 0;
int* p = &a;
int** p1 = &p;
test(&p); // Two levels down the pointer is an element or null
test(p1);A special secondary pointer
I mentioned it in the array pointer before , The array pointer can be regarded as a special secondary pointer , The values of the second level and the first level are the same .
#include<stdio.h>
void test(int** p) {}
void test1(int(*p)[]){} // there 10 Normal should add , In order to demonstrate the secondary pointer feature, there is no
int main(void) {
int arr[10] = { 0 };
int(*p)[10] = &arr;
test(&arr);
test(p);
test1(&arr);
test1(p);
return 0;
}边栏推荐
- 100 important knowledge points that SQL must master: management transaction processing
- Leetcode theme [array] -169- most elements
- PIP audit: a powerful security vulnerability scanning tool
- [Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
- Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Landingsite eband B1 smoke test case
- 【剑指 Offer】56 - I. 数组中数字出现的次数
- The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
- 2019 Nanchang (relive the classic)
猜你喜欢
![[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)](/img/07/6f2dfb543cb0ab4f27169da7e6ad07.jpg)
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
![[shutter] shutter layout component (wrap component | expanded component)](/img/a7/824a990235fc5ce67841ebdcf001fb.jpg)
[shutter] shutter layout component (wrap component | expanded component)

Ransack组合条件搜索实现

Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale

New feature of go1.18: trylock, which has been tossed n times
![[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)](/img/f7/cb41d159e5c5ef3f4f1b9468d52ccc.jpg)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)

地理探测器原理介绍

Oriental Aesthetics and software design

sql service 截取字符串
![[zero foundation I] Navicat download link](/img/23/e7808884152eeaf186fe756d6adac6.png)
[zero foundation I] Navicat download link
随机推荐
[shutter] shutter application theme (themedata | dynamic modification theme)
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
: last child does not take effect
Une semaine de vie
Market Research - current market situation and future development trend of night vision goggles for pilots
加了定位的文字如何水平垂直居中
Daily book CSO advanced road first exposed
Market Research - current market situation and future development trend of marine wet exhaust hose
100 important knowledge points that SQL must master: management transaction processing
Using emqx cloud to realize one machine one secret verification of IOT devices
#include<>和#include“”的区别
Evolution of messaging and streaming systems under the native tide of open source cloud
Destroy in beforedestroy invalid value in localstorage
Basic IO interface technology - microcomputer Chapter 7 Notes
图像基础概念与YUV/RGB深入理解
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
Ransack combined condition search implementation
【剑指 Offer】57. 和为s的两个数字