当前位置:网站首页>The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
The basis of C language grammar -- pointer (multidimensional array, function, summary) learning
2022-06-26 09:50:00 【Tanzanian auduvi Canyon expert】
Normal pointer :
Two dimensional array , Generally, there are several rows and columns ;
If more than one ordinary pointer is defined , This pointer only represents the address of the row , Instead of an element address , such as :
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int *p;
p=a; //
printf("%d\n",*p); // 1 The element values of the first row and the first column
p=a+1;
printf("%d\n",*p); // 4 The element values in the first column of the second row
You can define a pointer to a specified address :
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int *p;
p=&a[1][1]; // The address of the element in the second row and the second column
printf("%d\n",*p); // 5 The element values of the first row and the first column
p++;
printf("%d\n",*p); // 6 The element values in the second row and the third column
p=a+1; // The second line
printf("%d\n",*p); // 4 The element values in the first column of the second row


int main(int argc, char *argv[]) {
/* 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 */
int a[5][5];
int i,j;
for(i=0;i<5;i++){
for(j=0;j<5;j++){
// a[i][j]=i-j+1; // Non pointer version
*(a[i]+j)=i-j+1; // Pointer version
*(*(a+i)+j)=i-j+1; // Pointer version
if(i>=j){
// printf(" %d", a[i][j]); // Non pointer version
// printf(" %d", *(a[i]+j)); // Pointer version
printf(" %d", *(*(a+i)+j)); // Pointer version
}
}
printf("\n");
}
return 0;
}
Array pointer :
Define line pointer ( Array pointer ): You can use *(*(p+i)+j, Otherwise, the report will be wrong , Only use *(*(a+i)+j
int a[3][3]={
1,2,3,4,5,6,7,8,9};
int (*p)[3]; // Array row pointer


Several pointer operations on arrays :

Notice the commas in the figure , The execution order is from right to left , If it is a comma, change it to a multiplication sign , It's from left to right
int a[]={
1,2,3},y,*p=&a[2];
y=*--p;
y Value : 2
Logic :p The initial pointing subscript is 2 The address of , First --, Move to subscript 1, then * Value , The table below for 1 The address of , The value is 2
int a[]={
1,2,3,4,5,6},*p=a;
*p++ * *++p The value of is :3
Logic : Multiplication sign , From left to right , First *p=1, Then add the pointer 1, In execution ++p, The pointer is adding 1, And then take *++p=3 , Last 1*3=3
A function pointer :
int max(int a, int b){
}
int (*p)()
max(a,b) --> (*p)(a,b)
Pointer array :
Definition :
Each subscript variable is a pointer variable , It's an address , It is mainly used to handle variable length multiple strings .
understand : Pointer array is not the same concept as the previous array pointer , Pointer arrays are special in that all elements are an address
style :
int *b[3]={ a,&a[1] }
Pointer summary :

// Area of circle
double area(int r){
return 3.14*r*r;
}
int main(int argc, char *argv[]) {
double (*p)(); // Note that the type must be consistent with the function type , If the function is double, Here is int, The result will be 4199728.00000
p=area;
int i=2;
double result;
result=(*p)(i);
printf("%f",result); // 12.560000
return 0;
}
边栏推荐
- Deep learning (tentsorflow2. version) three good student performance problems (1)
- [Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network
- Abnormal record-23
- 【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort
- Common SQL add / delete / modify query statements
- 自动化测试——pytest本身及第三方模块介绍及使用
- pcl install
- Redis novice introduction
- GAN Inversion: A Survey
- c语言语法基础之——指针( 多维数组、函数、总结 ) 学习
猜你喜欢

【轨迹规划】Ruckig库的测试
How to correctly open the USB debugging and complete log functions of Huawei mobile phones?

Several connection query methods of SQL (internal connection, external connection, full connection and joint query)

#云原生征文# 在 Google Kubernetes Cluster 上使用 HANA Expression Database Service
![[trajectory planning] testing of ruckig Library](/img/c7/51c0f6dc3bf7c7fa4528118a4c32fa.png)
[trajectory planning] testing of ruckig Library
QPM suspended window setting information

Test instructions - common interface protocol analysis

install realsense2: The following packages have unmet dependencies: libgtk-3-dev

2021-11-29 quintic polynomial of trajectory planning

MapReduce & yarn theory
随机推荐
Detailed explanation of the network security competition questions (2) of the 2021 national vocational college skills competition (secondary vocational group)
节流,防抖,new函数,柯里化
[pulsar learning] pulsar Architecture Principle
LeetCode 0710. Random numbers in the blacklist - preprocessing implementation o (1) value
Badge series 5: use of codecov
爬虫相关文章收藏:pyppeteer 、Burpsuite
做测试需要知道的内容——url、弱网、接口、自动化、
PHP extracts TXT text to store the domain name in JSON data
c语言语法基础之——指针(字符、一维数组) 学习
Several connection query methods of SQL (internal connection, external connection, full connection and joint query)
Leetcode connected to rainwater series 42 (one dimension) 407 (2D)
Badge series 4: use of circle Ci
How to create an IE tab in edge browser
Joint Noise-Tolerant Learning and Meta Camera Shift Adaptation for Unsupervised Person Re-ID
深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)
jz2440---使用uboot燒錄程序
SQL 函数
c语言语法基础之——函数 小程序 求阶乘
The shutter tabbar listener is called twice
QPM performance monitoring components - General